This repository is a simple example of an implementation Clean Architecture using Python.
I am writing a series of Linkedin articles related to this project:
- Python Clean Architecture In-memory CLI implementation: I wrote this article explaining the Clean Architecture, its layers and a Python implementation of an in-memory CLI.
- Error Handling, Logging and Validation implementation in Python Clean Architecture: I wrote this article about error handling, logging and validation, including some Python best practices around these topics. I complemented our Python Clean Architecture implementation with those topics.
- Python Clean Architecture Flask Web API In-memory implementation: In this article, I wrote about basic Flask concepts, Flask blueprints and how to test a Flask application. I also talked about the addition of a Flask web API to our Python Clean Architecture implementation.
- Python Clean Architecture Flask Web API Postgresql implementation: In this article, I wrote about about the inclusion of the Flask PostgreSQL flavour in my Python Clean Architecture repository. I talked about the SQLAlchemy model, Alembic database migrations, using .env files to protect sensitive information and also how to close the database connection when the http connection is closed.
Also, check this repository where you can find examples and explanations of Python best practices that complement this repository and its articles.
git clone https://github.com/claudiosw/python-clean-architecture-example-1.git
python -m venv venv
venv\Scripts\activate
source venv/bin/activate
pip install -r requirements.txt
pre-commit install
python .\cli_memory_process_handler.py
python .\flask_memory_process_handler.py
To use the PostgreSQL flavour of our app, we need to install PostgreSQL software. It can be in other machine as well. We will need a database and a user to access this database.
Create a .env file. Use the .env.example file as a template. Set the values considering your scenario.
With the PostgreSQL database installed and configured, you can apply the database migrations with the command below:
alembic upgrade head
python .\flask_postgresql_process_handler.py
You can access the API documentation here.
You can see the documentation of this project generated by Sphinx in here.
I hope this repository and my article series were valuable to you. If that was the case, please star it.
If you want to contact me, reach me on LinkedIn or Twitter.
I am looking for a Python position. I also offer paid mentoring.