Tag archive for: Python

How to paginate MongoEngine records in your Python 3 Flask application

Flask and MongoEngine help makes development work easier.

One common task in the development of backend applications is the pagination of database records. Without pagination, the application server can run out of memory while generating a response from the database records.

This post discusses a way to paginate MongoEngine records in your Python 3 Flask application using the facilities provided by the Flask-MongoEngine extension.


How to deploy Python 3 Flask application on Raspberry Pi 3 with Raspbian Stretch Lite, Nginx, Supervisor, Virtualenv and Gunicorn

Raspberry Pi 3 Model B boards make good gifts for programmers and if someone had gifted you with one, you may want to use it as a control center for interacting with various IoT sensors and devices at home.

In such a situation, you may want to build a Python 3 Flask application to present the web interface for accessing the control center.

After you had built that Python 3 Flask application, the next step will be to deploy it on your Raspberry Pi 3 for serving HTTP requests.

This post discusses how you can deploy a Python 3 Flask application on Raspberry Pi 3 with Raspbian Stretch Lite, Nginx, Virtualenv and Gunicorn.

How to serve static files with Python 3 + Flask

Python Flask is a good microframework for building a minimal viable product to validate our ideas on the Internet. A modern web application encompasses documents that tell the web browser how to build the visuals of our web application and communicate with our server backend. Such documents are usually static in nature and are served as they are to the web browser without any processing from the server end.

Comparing setting up an instance of the Nginx server with adding code in our Flask application, the latter can be a more convenient way for us to realise our minimal viable product. This post documents the proof of concept that I did to serve static files with Python 3 and Flask.

A platform independent way to set your Python Path for your Python applications

In a software development house where desktop computers run Microsoft Windows while servers run Linux, software developers will have to ensure that the Python code that they wrote on their Windows machine can run on the deployment servers which are running Linux.

One unavoidable task for Python application developers is the importing of functionalities that are contained in other Python scripts. In order for the Python interpreter to find the Python scripts that are referenced by Python import statements, the Python Path will need to contain the URLs of the directories that contain the Python scripts to be imported.

How to sort a python dictionary by keys

I am a fan of hash tables when I need to implement logic that augments computation results to a common data structure that need to be used across several function bodies. The ability of the hash table in providing constant access by key helps me in keeping my logic from taking too much time to complete.

Python’s version of hash tables are known as a dictionaries or associative arrays. Apart from augmenting computation results to values of my Python dictionaries, one common task that I often perform is sorting the results by the dictionary keys. In this post, I document how I can sort my Python dictionary by its keys.

Techcoil Recommends

Python 300x250