Level up your Twilio API skills in TwilioQuest, an educational game for Mac, Windows, and Linux. Download Now
Build the future of communications.
Start building for free
  • By Miguel Grinberg
    Working with Environment Variables in Python Working with Environment Variables in Python

    Environment variables provide a great way to configure your Python application, eliminating the need to edit your source code when the configuration changes. Common configuration items that are often passed to application through environment variables are third-party API keys, network ports, database servers, and any custom options that your application may need to work properly.

    In this article I’m going to share some of the techniques and tools available in Python to work with environment variables.

    How to access environment variables from Python

    Using the os.environ dictionary

    In Python, the os.environ dictionary contains all the environment variables. The simplest way to retrieve a variable from inside your application is to use the standard dictionary syntax. For example, this is how you can access an environment variable named USER:

    >>> import os
    >>> user = os.environ['USER']
    >>> user
    'miguel'
    

    Using this method, if you try to import an environment variable …

    Read More
  • By Miguel Grinberg
    Programming the Raspberry Pi Pico Microcontroller with MicroPython Programming the Raspberry Pi Pico Microcontroller with MicroPython

    With the release of the Raspberry Pi Pico, the Raspberry Pi Foundation has expanded its product offering beyond their highly successful line of mini-computers and went even smaller by entering the microcontroller market.

    Raspberry Pi Pico

    Unlike the Raspberry Pi, which functions as a general purpose computer and runs the popular Linux operating system, the Pico is a much more primitive device that lacks a central operating system and can only be programmed to perform specific tasks or control connected peripherals, usually as part of an embedded system or Internet of Things device.

    While most microcontrollers can only be programmed in C or C++, the Pico also offers support for MicroPython, a slimmed down version of Python that is designed specifically for small devices. This makes it a great choice for beginners who want to design their own devices but don’t have the patience or interest to learn low-level programming.

    In …

    Read More
  • By Miguel Grinberg
    Browser Messaging with WebRTC and the Twilio Data Track API Browser Messaging with WebRTC and the Twilio Data Track API

    Twilio Programmable Video is a robust service based on the WebRTC open standard, which enables real-time communications for web browsers and mobile devices. One of the lesser known features of WebRTC is the ability to stream data in addition to video and audio. The data track is often used to send information that annotates or complements the media streams, but it is also possible to build applications that do not use video and audio and just use the WebRTC data tracks to communicate.

    In this tutorial you are going to learn how to use the Twilio Data Track API while building a small browser-to-browser messaging application. The application is going to have a small Flask back end dedicated to the generation of Access Tokens, and a vanilla JavaScript front end that will be able to send real-time notifications to other running instances of the application.

    project demo

    Requirements

    To build this …

    Read More
  • By Miguel Grinberg
    How to Check your Twilio Account Balance in Python How to Check your Twilio Account Balance in Python

    Twilio APIs make it easy to add communication features to your application, but to consume these APIs you have to keep track of your spending and ensure your account balance stays above zero.

    Your balance is available in the main page when you log in to your Twilio Console, but having to actively monitor your account is tedious and inconvenient. In this tutorial you are going to learn how to retrieve your account balance using Python, which will allow you to build automated account balance monitoring within your application!

    Prerequisites

    To follow this tutorial you will need:

    • Python 3.6 or newer. If your operating system does not provide a Python interpreter, you can go to python.org to download an installer.
    • A free or paid Twilio account. If you are new to Twilio get your free account now! This link will give you $10 when you upgrade.

    Creating a Python …

    Read More
  • By Miguel Grinberg
    Generating Twilio Access Tokens in Python Generating Twilio Access Tokens in Python

    Several Twilio services can be accessed from a web application running on the browser, but given that this is an inherently insecure platform, the authentication flow is different than for server-based applications.

    An application running on the browser needs to obtain an Access Token from your server, and then use this token to authenticate. This is more secure because it prevents you from having to expose your Twilio account credentials in the browser, and also because access tokens have a short lifespan. In this tutorial you are going to learn how this authentication flow works and how to generate access tokens for Twilio services using Python and the Flask framework.

    Tutorial requirements

    To follow this tutorial you will need:

    • Python 3.6 or newer. If your operating system does not provide a Python interpreter, you can go to python.org to download an installer.
    • A free or paid Twilio account. If you …
    Read More
  • By Miguel Grinberg
    Server Push in 5 Easy Steps with Flask, React and Twilio Sync Server Push in 5 Easy Steps with Flask, React and Twilio Sync

    When considering a server push solution for your web application, you will likely evaluate WebSocket, HTTP long-polling, Server-Sent Events and maybe even Socket.IO. In this tutorial I want to introduce you to yet another option that you may not know: Twilio Sync. Sync is a cloud synchronization service that works across browsers and mobile devices and that it is incredibly easy to integrate with your application.

    To learn how Twilio Sync works, we are going to add server push capability to a small web application that has a React front end and a Python and Flask back end. We’ll get the job done in just five easy steps!

    server push demo

    Note that “server push” in this context refers to technologies that allow web servers to initiate an exchange with clients and “push” events, notifications or data to them. Do not confuse this with “HTTP/2 Server Push”, which is …

    Read More
  • By Miguel Grinberg
    Add Text Chat To Your Video Calls With The Twilio Conversations API Add Text Chat To Your Video Calls With The Twilio Conversations API

    If you implemented a video calling application using the Twilio Programmable Video API, you may find that during a call you want to share textual information with the other participants. This could be a link to a document, or even a reaction emoji. In this article you are going to learn how to take your video application to the next level by adding a chat room with the Conversations API.

    Video call with chat demo

    Tutorial requirements

    This is the third article in my series of Programmable Video tutorials, so we are going to take advantage of the video chat application built in the previous two installments and add the chat room feature to it. This application uses a vanilla JavaScript front end and a Python back end. To run this application on your computer you need the following requirements:

    • Python 3.6 or newer. If your operating system does not provide a Python …
    Read More
  • By Miguel Grinberg
    Build a Multi-Room Web Chat Application with Flask, React and Twilio Conversations Build a Multi-Room Web Chat Application with Flask, React and Twilio Conversations

    The Twilio Conversations API is a great way to build a unified messaging solution that works across SMS, MMS, WhatsApp, web and mobile chat. In this tutorial you will learn the basics of the Conversations API by creating a web chat application with support for multiple chat rooms.

    Project demo

    The main features of the application we will build are:

    • A Flask backend that logs users in.
    • A command-line interface to manage your chat rooms.
    • A Rect front end that allows your users to chat on the different chat rooms.

    Requirements

    To follow this tutorial you need the following components:

    • Python 3.6 or newer. If your operating system does not provide a Python interpreter, you can go to python.org to download an installer.
    • Node.js 14 or newer. Review the installation instructions for your operating system.
    • The Yarn package manager for Node.js. Review the installation instructions for your operating system.
    • A Twilio account. …
    Read More
  • By Miguel Grinberg
    Using the Twilio Python Helper Library in your Async Applications Using the Twilio Python Helper Library in your Async Applications

    If you are using an asynchronous web server with your Python application, you are bound by the first rule of async development, which is to never call functions that block. So what do you do when you need to use packages such as the Twilio Python Helper Library, which has no asynchronous version?

    In this article I’m going to show you some of the options that you have to safely integrate Twilio and similar clients with your async application.

    What is the problem?

    Before I go into the solutions, I thought it would be good to give a quick review of the issues with blocking in asynchronous applications.

    At the core of every async application there is the loop, an efficient task manager and scheduler that ensures that the CPU is shared as fairly as possible among all the running tasks. The type of multitasking used by async …

    Read More
  • By Miguel Grinberg
    Construa um Chatbot para WhatsApp com Python, Flask e Twilio Construa um Chatbot para WhatsApp com Python, Flask e Twilio

    Um chatbot é um aplicativo de software capaz de conduzir uma conversa com um usuário humano por meio de linguagem escrita ou falada. O nível de "inteligência" entre os chatbots varia muito. Enquanto alguns chatbots têm um entendimento bastante básico da linguagem, outros empregam algoritmos sofisticados de inteligência artificial (IA) e aprendizado de máquina (ML) para alcançar um nível de conversação quase humano.

    Nesse tutorial eu vou mostrar a você como é fácil construir um chatbot para Whatsapp usando a API da Twilio para WhatsApp e Flask framework para Python. Abaixo você pode ver um exemplo de interação com o chatbot:

    project demo

    Requisitos do Tutorial

    Para seguir esse tutorial você precisa dos seguintes componentes:

    • Python 3.6 ou mais recente. Se seu sistema operacional não tem um interpretador Python, você pode ir em python.org  para baixar o instalador.
    • Flask. Nós vamos criar uma aplicação web que responde mensagens vindas do WhatsApp. …
    Read More
  • Newer
    Older
    Sign up and start building
    Not ready yet? Talk to an expert.