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
.env
file at the root of the project (See the file.env_example
in 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:latest
2.1. Example: To run a container named
mypostgres
on the port5433
with the database namemydb
, the usernameadmin
and the passwordroot
the 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.env
file -
Add the other environment variable
API_URL="http://localhost:4200"
(or another port different of4200
) to run the API
That's it. :)