Articles about Python

Python Logo

Python is one of the most versatile programming languages in the world. With Python, you can control electronics, build web applications and perform machine learning.

In this page, you can find articles on Python references, coding and application setup.

How to download a file via HTTP POST and HTTP GET with Python 3 requests library

When you are building a HTTP client with Python 3, you could be coding it to upload a file to a HTTP server or download a file from a HTTP server.

Previously, we discussed how to upload a file and some data through HTTP multipart in Python 3 using the requests library. In this post, let’s see how we can download a file via HTTP POST and HTTP GET.

How to install python3-venv on Ubuntu 16.04

Since Ubuntu 16.04 is a very popular operating system, it is one operating system that you will likely come across when you are building software with Python 3. For example, if you want to get a Nvidia Jetson TX2 developer kit today, you will find yourself dabbling with Ubuntu 16.04.

On the other hand, the venv module of Python 3 is one recommended way to create virtual environments for our Python 3 projects.

In case you need it, this post describes how to install python3-venv on Ubuntu 16.04.

How to use Flask-APScheduler in your Python 3 Flask application to run multiple tasks in parallel, from a single HTTP request

When you build an API endpoint that serves HTTP requests to work on long-running tasks, consider using a scheduler. Instead of holding up a HTTP client until a task is completed, you can return an identifier for the client to query the task status later. In the meantime, your HTTP server can offload the task to a scheduler which will complete it and update the status.

When you are building your HTTP server with Python 3 Flask, Flask-APScheduler gives you the facilities to schedule tasks to be executed in the background.

In this post, we look at how we can get Flask-APScheduler to run multiple tasks in parallel, from a single HTTP request.

How to set environment variables for your Python application from PyCharm

The Twelve-Factor App methodology recommends storing configurations in the environment.

When you follow this methodology and want to run your Python application from PyCharm, you need to create a customised run configuration.

In case you need it, this post shows how to set environment variables for your Python application from PyCharm.

How to associate a virtual environment with a Python project in PyCharm

When it comes to Python development, PyCharm is my favourite IDE.

Before working on a new Python project, I like to create a virtual environment and associate it with the corresponding PyCharm project. In case you like this mode of operation, this is how you can associate a virtual environment with a Python project in PyCharm.

How to read temperature and humidity from a DHT11 sensor that is connected to a Raspberry Pi 3

I had always wanted to measure the temperature and humidity of the environment where my herbs are grown at.

Since I had a few pieces of Raspberry Pi 3 lying around the house, I decided to use one of them to measure the temperature and humidity of the area of the house where my herbs are.

An additional sensor is required to measure the temperature and humidity of the environment. Therefore, I went to AliExpress and got a DHT11 sensor. By connecting a DHT11 sensor to my Raspberry Pi 3, I can give it the ability to read the temperature and humidity of its environment.

Given these points, I created this post to show how to read temperature and humidity from a DHT11 sensor that is connected to a Raspberry Pi 3.

In order for us to check the temperature and humidity from the DHT11 sensor, we will build a simple Flask application that returns the temperature and humidity values as HTTP responses to HTTP clients.

Building a Raspberry Pi 3 prototype camera that takes a picture at the press of a button

A fun way to test your Raspberry Pi Camera on your Raspberry Pi 3 is to build a prototype that takes a picture at the press of a button. Through such an activity, we will be able to experience:

  • connecting a button to the GPIO ports on a Raspberry Pi.
  • setting up a camera through the CSI interface of a Raspberry Pi.
  • preparing an operating system, such as Raspbian Stretch Lite , for running Raspberry Pi projects.
  • coding a Python 3 script that interacts with the GPIO port and camera on a Raspberry Pi.
  • running a Python 3 script when Raspberry Pi powers on.

Given these points, this post shows how you can build a Raspberry Pi 3 prototype camera that takes a picture at the press of a button.

How to use Python 3 Pillow on Raspbian Stretch Lite to compress your jpeg image

When you are building a Raspberry Pi camera project, you may want to compress the images captured from the camera to reduce the time to upload your image to a server endpoint. Moreover, when you connect your Raspberry Pi to your iPhone Personal WiFi hotspot, you will want to incur minimal mobile bandwidth charges from demonstrating your Raspberry Pi project in your class.

You may have either:

In this case, you will have the option to use Pillow, a fork of Python Imaging Library, to compress your jpeg image.

How to upload a file and some data through HTTP multipart in Python 3 using the requests library

Undeniably, the HTTP protocol had become the dominant communication protocol between computers.

Through the HTTP protocol, a HTTP client can send data to a HTTP server. For example, a client can upload a file and some data from to a HTTP server through a HTTP multipart request.

If you are building that client with Python 3, then you can use the requests library to construct the HTTP multipart request easily.

In case you need it, this is how we can upload a file and some data through HTTP multipart in Python 3 using the requests library.