Python for Beginners - Part 6 - Web API connection, Dictionary, Environment Variable and Decorator

lucianopereira86

LUCIANO DE SOUSA PEREIRA

Posted on October 16, 2019

Python for Beginners - Part 6 - Web API connection, Dictionary, Environment Variable and Decorator

python_titulo
Last part of articles about the Microsoft's Python for Beginners series.
All the examples from the playlist are available in this GitHub repository: Python Examples.

Objective

You will learn how to make connect with web APIs, manipulate dictionaries, read environment variables and use decorators.
A Python file was created to demonstrate each example.

Topics

api/post.py

Making a POST request to a web API.
The example file was created inside of a folder named api.

code32

First, install the requests library:

pip install requests

The result will be:

code33

Then, run this command:

python .\examples\api\post.py

The result will be:

code34

dictionary.py

Creating and manipulating dictionaries.

code35

Executing the command below:

python .\examples\dictionary.py

The result is:

code36

keys.py

Reading environment variables.

code37

Create a .env file containing a secret key.

code38

Update the requirements.txt file by adding python-dotenv.

code39

Let's use a virtual environment again by executing the commands below:

python -m venv venv

.\venv\Scripts\Activate.ps1

Install the python_dotenv package inside the venv:

pip install -r requirements.txt

The result will be:

code40

Finally, run this command:

python .\examples\keys.py

The result will be:

code41

decorators.py

How to use decorators in functions.

code42

Run the command:

python .\examples\decorators.py

The result will be:

code43

Conclusion

We have finally ended this series!
Now you have the basics to start working with Python.

💖 💪 🙅 🚩
lucianopereira86
LUCIANO DE SOUSA PEREIRA

Posted on October 16, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related