Skip to content

lealre/fastapi-testcontainer-asyncpg

Repository files navigation

Testcontainers with FastAPI and asyncpg

This repository is a simple example application of how to test asynchronous FastAPI routes using a Docker instance of PostgreSQL with asyncpg as the database driver. It is done by using testcontainers-python.

You can check a more detailed text about the repository here.

How to run this project

This repo was created using uv and uses Python version 3.12.3.

How to install uv.

  1. Clone the repo locally and access the project folder:

    git clone https://github.com/lealre/fastapi-testcontainer-asyncpg.git
    cd fastapi-testcontainer-asyncpg
  2. Run the command to serve the API on port 8000. It will automatically create and activate the virtual environment:

    uv run -m fastapi dev src/app.py

    To test the endpoint, access http://localhost:8000/docs.

  3. Run the tests:

    uv run pytest -vv

About

Testing async FastAPI routes with PostgreSQL and asyncpg using testcontainers-python.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages