Skip to content

Fork of https://github.com/0xTheProDev/fastapi-clean-example, updated to work with Python 3.12. Has improved Windows compatibility. (Removes some critical security vulnerabilities as a side-effect of updating all dependencies!)

License

Notifications You must be signed in to change notification settings

mbjd05/fastapi-clean-template-ng

Repository files navigation

fastapi-clean-template-ng

Description

Example Application Interface using FastAPI framework in Python 3

This example showcases Repository Pattern in Hexagonal Architecture (also known as Clean Architecture). Here we have two Entities - Books and Authors, whose relationships have been exploited to create CRUD endpoint in REST under OpenAPI standard.

About this fork

All actual work was done for Python 3.8 by 0xTheProDev, in his amazing fastapi-clean-example. I just did the following to update it to 3.12:

  • Update dependencies to Python 3.12 versions.
  • remove outdated dependencies and install their newer equivalents (pydantic => pydantic-settings).
  • Make pipfile install on Windows (the pipfile no longer tries to install the unsupported uvloop as a dep to uvicorn on Windows).
  • Install winloop instead of uvloop on windows for when no hot-reload is needed.
  • Add platform agnostic run.py entrypoint script with hot-reloading by default and an optional --no-reload flag, which automatically picks the optimal event loop to use depending on current platform and 'reload choice'.
  • update installation instructions to clarify the process for Windows.

Installation

  • Install all the project dependency using Pipenv:

    $ pipenv install --dev
    • If you're on Windows, install uvicorn manually afterwards, without uvloop, which doesn't run on Windows. run.py will use winloop instead when using the --no-reload flag, as it unfortunately does not support uvicorn's hot-reloading at this time. If you want hot-reloading, the default asyncio event-loop will be used automatically instead by ommiting the flag.

      $  pipenv run pip install uvicorn --no-binary uvicorn
  • Run the server:

    $ pipenv run python run.py
  • Run the server without hot-reloading:

    $ pipenv run python run.py --no-reload

    (This enables the faster winloop event-loop on Windows)

  • You can also open a shell inside virtual environment:

    $ pipenv shell
  • Open localhost:8000/docs for API Documentation

  • Open localhost:8000/graphql for GraphQL Documentation

Note: In case you are not able to access pipenv from you PATH locations, replace all instances of pipenv with python3 -m pipenv.

Testing

For Testing, unittest module is used for Test Suite and Assertion, whereas pytest is being used for Test Runner and Coverage Reporter.

  • Run the following command to initiate test:
    $ pipenv run pytest
  • To include Coverage Reporting as well:
    $ pipenv run pytest --cov-report xml --cov .

License

© MIT License

About

Fork of https://github.com/0xTheProDev/fastapi-clean-example, updated to work with Python 3.12. Has improved Windows compatibility. (Removes some critical security vulnerabilities as a side-effect of updating all dependencies!)

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Languages