Spaces Not Tabs: Our Favorite Python Tutorials for May 2019
Python programmers love to help – the community publishes detailed tutorials for their fellow developers every day. Over the last month, we’ve been collecting some of those posts we found most helpful.
Each tutorial is easy enough for beginner-level programmers to follow. More experienced developers should be able to breeze through the code while building a useful project, or use them as convenient refreshers.
Whichever bucket you belong to, enjoy the posts!
Exercising, or Slacking? Build a Python Bot for Either
The term "bot" feels so 2017 in this community. However, they are still a great way to learn how to build Python applications.
- Create Your Own Personal Training Exercise Bot with Python, Zappa, AWS and Twilio SMS by Matthew Vielkind via Twilio
- Build a Slack Bot that Mimics Your Colleagues by Casey Kinsey via Lofty Labs
Use Bokeh to Visualize All the Data!
Bokeh, the wonderful Python visualization library ...
How to Send WhatsApp Messages from Java Applications with Twilio
WhatsApp is a global messaging service that helps billions of people communicate with each other. Applications can now also programmatically interact with people on the service using the Twilio Messaging API and Twilio's Java Helper Library. Let's learn how to quickly send messages to people from a new or existing Java application.
Our local development environment needs the following dependencies to properly send WhatsApp messages from Java.
- Java SE version 7 or higher
- A free Twilio account with an activated WhatsApp Sandbox
- The Twilio Java Helper Library
First, install Java on your development machine if you do not already have it. You can also read this detailed tutorial on setting up your Java development environment if you are having trouble.
Take note of your Account SID and Auth Token when you log ...
How To Send a WhatsApp Message in 30 Seconds with Python
WhatsApp is an over-the-top (OTT) messaging service widely used throughout the world. In this tutorial, we will learn how to quickly send WhatsApp messages through the Twilio Messaging API with reusable code that can be added to any Python application.
Development Environment Setup
We need the following dependencies installed on our local development environment to send WhatsApp messages.
- Python version 2 or 3
- A free Twilio account with an activated WhatsApp Sandbox
- The Twilio Python Helper Library
If you do not have Python already installed on your machine, go to the Python downloads page and install the latest version now.
After you log into the Twilio Console, take note of your Account SID and Auth Token. The Account SID is a unique identifier for your account while the Auth Token is a secret key ...
How to Send SMS Text Messages with AWS Lambda and Python 3.6
Amazon Web Services (AWS) Lambda is a usage-based service that can run arbitrary Python 3.6 code in response to developer-defined events. For example, if a new JPEG file is uploaded to AWS S3 then AWS Lambda can execute Python code to respond to resize the image on S3.
Let’s learn how to use AWS Lambda with a manual test event trigger to send outbound text messages via a Python Lambda function that calls the Twilio SMS REST API.
Getting Started with AWS Lambda
Sign up for a new Amazon Web Services account, which provides a free tier for new users, or sign into your existing AWS account.
After you sign up go to the main Console page that looks like the following screen.
As shown in the screenshot, use the search box with the text “lambda” to find Lambda on the list of services. Click on Lambda to ...
How to Dial and Answer Phone Calls with Spark and Java 8 in IntelliJ
Java web applications can easily dial and receive phone calls by combining the Spark web framework with the Twilio Voice API. Our example phone calls will say a snippet of text then play an MP3 file, but they can easily be modified to provide other useful actions like gathering user input from the number pad or creating conference calls.
Our Project Tools
Our Spark web app will use the Java 8 JDK and Apache Maven so make sure you have those tools installed. If you need to get Java 8 and Apache Maven installed on your Windows machine, check out this tutorial (you can skip over the GWT bits). We will also need the following tools throughout this walkthrough:
How to Install Java 8, Apache Maven and Google Web Toolkit on Windows 10
Do you want to get started developing Java web applications that use Google Web Toolkit (GWT)? This guide walks through how to install a Windows 10 development environment so you can start building your projects.
Tools We’ll Need
We’ll need to install and configure several tools for our development environment:
- Java 8 Java Development Kit (JDK)
- Apache Maven build and configuration tool
- Google Web Toolkit (GWT) web framework
Let’s get started by downloading and installing version 8 of the Java JDK.
Java 8 JDK
Head over to the Java 8 JDK downloads page in your web browser. Read and accept the licensing agreement then proceed with the download for the latest release of the Windows x64 Java SE Development Kit.
When the download completes, run the executable. Allow the installer to make changes to your system.
Move through the installer and when you reach the following screen ...
Localhost Tunneling with Ngrok on Mac OS X
A localhost tunnel comes in handy when you want to share an application running in your local development environment via a publicly-accessible URL. In this quick 2 minute video we will learn how the localhost tunneling tool Ngrok works then download and run it on Mac OS X:
Now you’re ready to share your local in-progress applications with others before you perform a full-blown deployment.
Links & More Resources
We used a couple of resources in the above video:
- Ngrok, the localhost tunneling tool by Alan Shreve
- Python 2.7 SimpleHTTPServer built into stdlib (Python 3 replaces SimpleHTTPServer with http.server)
Learn more about how to configure and use Ngrok with these tutorials:
- Test Your Webhooks Locally with Ngrok
- 6 awesome reasons to use ngrok when testing locally
- How to set up your Python and Flask development environment, including Ngrok
Now that you have Ngrok running on your Mac ...
First Steps with Python and Bottle
Do you want to build your first web application with Python? Or have you been working with a full-featured web framework such as Django or Pyramid and want to try out a microframework? Take four minutes to watch this video and check off “get started using the Bottle web framework” from your 2016 to-do list:
You can snag the code in the video via this GitHub Gist or just copy from here into a file named
import bottle from bottle import route, run, Response app = bottle.default_app() @route("/") def index(): """Returns standard text response to show app is working.""" return Response("My Bottle app is up and running!") if __name__ == '__main__': run(host="127.0.0.1", port=5000, debug=False, reloader=True)
Make sure to
pip install bottlefrom PyPI and then run the following command:
That’s it, 15 lines of ...!-->
How to Make and Receive Phone Calls with Python, Bottle and Twilio Voice
Python web applications that combine the Bottle web framework with the Twilio Voice API can easily make and receive phone calls. Our calls will read a snippet of text then play an MP3 file. The call instructions can be modified to provide other useful actions such as gathering input from the number pad or putting all callers together in a conference call.
Our Project Tools
Our Bottle application will need either Python 2 or 3 to be installed. Python 3 is recommended for new applications. We will also need the following tools throughout this walkthrough:
- Bottle web framework for serving HTTP requests
- Ngrok to create a localhost tunnel to our local development environment
- A free Twilio account to use the Voice web API
- Twilio Python helper library
You can snag all the code for this tutorial in the python-twilio-example-apps GitHub repository. Copy and modify the code however you want – it ...
Getting Started with Python, Bottle and Twilio SMS / MMS
Python applications can easily send and respond to text and picture messages using a web API. Outbound messages are sent through Twilio’s RESTful API, while inbound messages are received by your application when Twilio makes an HTTP POST request. We will walk through how to set up a Bottle web app to handle both SMS and MMS messages.
Tools We Need
You’ll need Python 2 or 3. Although, Python 3 is recommended by the developer community for all new applications. Install one of those two Python versions on your system. We also need the following:
- The Bottle web framework
- Ngrok for localhost tunneling to our web app while it is running on our local development environment
- A free Twilio account to use the messaging API and receive webhooks
- The open source Twilio Python helper library and
- TwiML documentation for responding to inbound Twilio POST requests
All the code ...