This repository contains the code examples with adaptions of the book "Architecture Patterns with Python". The link of the book is here
- Python 3.8+
- Pytest
- PostgreSQL
- SQLAlchemy
- Clone the project to your local machine
- Go to the directory you want and create a virtualenv with the command
python -m venv <your_virtualenv> - Active your virtualenv with the command
source <your_virtualenv>/bin/activate - Go to the project root and install project dependencies with the command
pip install -r requirements.txt - Create a
.envfile at the root of the project (See the file.env_examplein this repository)
Done!! Now you need to run a docker container with Postgres
- Firstly, install Docker. If you already have it installed, skip this step. Otherwise, check the official documentation to install
-
Create a PostgreSQL container with the command
docker container run -d -p <host_port>:5432 --name <name_of_container> -e POSTGRES_USER=<your_user> -e POSTGRES_PASSWORD=<your_password> -e POSTGRES_DB=<your_db> postgres:latest2.1. Example: To run a container named
mypostgreson the port5433with the database namemydb, the usernameadminand the passwordrootthe command is:docker container run -d -p 5433:5432 --name mypostgres -e POSTGRES_USER=admin -e POSTGRES_PASSWORD=root -e POSTGRES_DB=mydb postgres:latest -
After that, add the environment variable
POSTGRES_URL="postgresql+psycopg2://user:password@host:port/dbname"into your.envfile -
Add the other environment variable
API_URL="http://localhost:4200"(or another port different of4200) to run the API
That's it. :)