Skip to content

dbaber/cosmicpython-fastapi

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Example application code for the python architecture book

https://github.com/cosmicpython/book

https://github.com/cosmicpython/code

Examples have been refactored. Flask has been replaced with FastAPI. Asynchronous ORM has been used.

Requirements

  • docker with docker-compose
  • for chapters 1 and 2, and optionally for the rest: a local python3.7 virtualenv

Building the containers

(this is only required from chapter 3 onwards)

make build
make up
# or
make all # builds, brings containers up, runs tests

Creating a local virtualenv (optional)

python3.7 -m venv .venv
poetry install
poetry shell # or source .venv/bin/activate

Running the tests

make test

Makefile

There are more useful commands in the makefile, have a look and try them out.

Running a server locally

(since chapter 06)

poetry shell
cd <chapter folder>
export PYTHONPATH=$(pwd)/src:$(pwd)/tests
make postgres
uvicorn allocation.entrypoints.main:app --reload
pytest

Debugging

(since chapter 06)

VS Code launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: FastAPI",
            "type": "python",
            "request": "launch",
            "module": "uvicorn",
            "args": [
                "allocation.entrypoints.main:app",
                "--reload"
            ],
            "jinja": true,
            "justMyCode": true,
            "env": {
                "PYTHONPATH": "${cwd}/chapter_06_uow/src" // change to the selected chapter
            }
        }
    ]
}

Run a web-server locally.

https://fastapi.tiangolo.com/tutorial/debugging/

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 97.0%
  • Makefile 2.1%
  • Dockerfile 0.9%