Skip to content

Repository files navigation

Python FastAPI App

A FastAPI complete application with nice features and tests.

Test

codecov

What is included

  • Senior organization support
  • Database support
  • Scheduler jobs support
  • Test, mock and code coverage support
  • Service layer support
  • Pydantic support
  • Rate limiter support
  • CORS support
  • Static files support
  • Docker support (single and compose)
  • Ready for production
  • Support for Python version from 3.10 to 3.14

Use Cases

APIs are essential for various types of applications, including:

  • Mobile applications
  • Progressive Web Applications (PWA)
  • Single Page Applications (SPA)
  • Microservices
  • Internet of Things (IoT) applications
  • Desktop applications that require online functionalities
  • JAMstack websites and applications
  • Low-Code and No-Code services like Bubble, FlutterFlow and others

Start Locally

To start locally execute:

uvicorn main:app --host 0.0.0.0 --port 8000 --log-level debug --reload

or

make start

Docker Single

To build and start docker in single mode:

docker build -f Dockerfile.web -t fastapi-app .
docker run --rm -v ./:/app -p 8000:8000 fastapi-app

or

make docker-single-build
make docker-single-start

To use a different database url when run:

docker run --rm -v ./:/app -p 8000:8000 -e DATABASE_URL="sqlite+aiosqlite:///./other.db" fastapi-app

Docker Compose

To build and start docker compose with application and database:

docker compose build
docker compose up -d

or

make docker-compose-build
make docker-compose-start

To stop docker compose:

docker compose down

or

make docker-compose-stop

Tests

To run tests execute:

python3 -m pytest

or

make test

To run tests execute with code coverage:

python3 -m pytest --cov=. --maxfail=1 tests/

or

make test-cov

API Tester

Once the API server is running, you can test your APIs by accessing the following URL:

http://localhost:8000/docs

Database

The project includes a sample database model with the following structure:

CREATE TABLE my_model (
    id SERIAL PRIMARY KEY,
    field1 VARCHAR(255) NOT NULL,
    field2 BOOLEAN NOT NULL DEFAULT FALSE,
    created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);

This model demonstrates:

  • Auto-incrementing primary key (id)
  • String field with maximum length of 255 characters (field1)
  • Boolean field with default value (field2)
  • Automatic timestamp for record creation (created_at)
  • Automatic timestamp for record updates (updated_at)

The database is configured to use SQLite by default, but you can easily switch to other databases by modifying the DATABASE_URL environment variable.

License

MIT

Copyright (c) 2024-2026, Paulo Coutinho

About

A FastAPI complete application with nice features and tests

Resources

Stars

70 stars

Watchers

4 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages