Posts related to Python

How to remove all packages installed by pip

29 March 2018

Sometimes you want to get rid of from all python packages. There is a quick and easy way to do this. The command below will also remove the packages installed via VCS.

pip freeze | grep -v "^-e" | xargs pip uninstall -y

Building a Flask REST API without using 3rd party extension

17 March 2018
In this tutorial, I’m going to show you how to create a simple REST API by using Flask framework. I will not bother you with any sort of advanced topic. Probably you won’t use this tutorial for any kind of production level product. I just want to show how easy can be to create a REST API with Flask. This tutorial aims to build a small and simple app. The entire app fits in a single file.

How to generate secrets in Python 3.6 and later

23 February 2018

There are a lot of ways to generate random values. But some of them are not suitable for secret keys. There is a new module named secrets in version 3.6 and later. You can use the code below to generate cryptographically strong random values.

import secrets

How to remove __pycache__ folders and .pyc files

20 February 2018

These folder and files are generated by python. You should add these to your VCS’s ignore file. But if you need to clean these manually, you can do with the command below:

find . | grep -E "(__pycache__|\.pyc|\.pyo$)" | xargs rm -rf