Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

FastPI application to manage tasks created during a coding dojo

License

Notifications You must be signed in to change notification settings

pygraz/2024-12-03-fastpi-dojo

Repository files navigation

FastAPI dojo

This is the source code produced during the PyGRAZ meetuo on 2024-12-03. It implements a REST API to manage tasks/todos.

The focus is on the API, so in order to keep things simple, storage uses a simple memory based repository. For a real world application, you might want to use SQLModel.

To look at how we implemented specific features, take a look at the following pull requests:

There is an additional pull request #11 to switch from poetry to uv for packaging. Vv has several advantages over poetry, but at the time of the dojo still had limited support in some IDEs. Also, the pull reuqets does not include instructions to set up the project with uv. Therefor it has not been merged. Still, you can check out this branch instead of main to explore the project.

Links

Project set up

  1. Install poetry.
  2. Set uo the project by running:
    poetry install
  3. Activate the pre-commit hooks by running:
    poetry run pre-commit install

To start the local development server, run:

poetry run fastapi dev main.py

You can omit the poetry run if you start from a poetry shell:

poetry shell
fastapi dev main.py

Testing

To run the test suite, run:

poetry run pytest

Code quality

To ensure the source code matches the quality standards of the project, run the pre-commit:

poetry run pre-commit run

To also check historic files committed earlier, run:

poetry run pre-commit run --all-files

PyCharm

If you open the project in PyCharm Professional, you can utilize the PyCharm FastAPI integration.

Dojo

For the coding dojo, we are going to build upon an existing FastAPI server (see #1))that essentially matches the first steps of the FastAPI tutorial.

The server will be extended to be able to manage tasks. Tasks have the following properties (see #3):

  • id: internal integer ID
  • title: text
  • description: text
  • completed_on: date, optional
  • due_on: date, optional
  • category: enum of: hobby, home, shopping, work

Tasks are comparable and hashable, so they can be compared and stored in sets and dicts. The basis for comparison is the id. For the implementation, see Task.__hash__(), __eq__, __lt__ and functools.total_ordering.

Tasks are collected in a TaskRepository that provides methods to:

  • add
  • get
  • list
  • remove

To make it easier we can create a demo task repository that already holds some data:

from tasks import TaskRepository

demo_repo = TaskRepository.new_demo()

About

FastPI application to manage tasks created during a coding dojo

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages