Skip to main content

FastAPI CRUD API

A modern, production-ready CRUD API built with FastAPI, SQLAlchemy 2.0, Alembic, and PostgreSQL (easily swappable with SQLite/MySQL).

Features:

  • Full CRUD operations
  • Async SQLAlchemy 2.0 + Pydantic v2
  • Automatic OpenAPI (Swagger) documentation
  • JWT authentication (optional, ready to enable)
  • Pagination, filtering, and sorting
  • Docker & Docker Compose support
  • Alembic migrations
  • Pre-commit hooks & Ruff linting
  • Testing with pytest + httpx

🚀 Quick Start

Prerequisites

  • Python 3.11+
  • Docker & Docker Compose (optional but recommended)

1. Clone the repository

git clone https://github.com/yosefalemu/fastapi-crud-api.git
cd fastapi-crud-api

2. Create and activate virtual environment

python -m venv venv
source venv/bin/activate    # Linux/Mac
# or
venv\Scripts\activate       # Windows

3. Install dependencies

pip install -r requirements.txt

4. Copy environment file

cp .env.example .env

Then edit .env with your settings (database URL, secret key, etc.)

5. Run migrations

alembic upgrade head

6. Start the server

uvicorn app.main:app --reload

Server will be available at: http://127.0.0.1:8000
Interactive docs:

docker compose up --build

The API will be available at http://localhost:8000

📋 API Endpoints (Example: Item resource)

Method Endpoint Description Auth Required
POST /items/ Create item No
GET /items/ List items (paginated) No
GET /items/{id} Get single item No
PUT /items/{id} Update item Yes (admin)
DELETE /items/{id} Delete item Yes (admin)
POST /auth/token Login & get JWT token No

Full interactive documentation available at /docs

🧪 Running Tests

pytest

Or with coverage:

pytest --cov=app

🔧 Environment Variables (.env)

DATABASE_URL=postgresql+asyncpg://user:password@localhost:5432/fastapi_crud
SECRET_KEY=your-super-secret-jwt-key-here
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
ENVIRONMENT=development

🗄️ Database Migrations (Alembic)

# Create a new migration
alembic revision --autogenerate -m "description"

# Apply migrations
alembic upgrade head

# Downgrade
alembic downgrade -1
pre-commit install

This project uses:

  • Ruff (linter & formatter)
  • Black
  • mypy
  • flake8

📁 Project Structure

.
├── app/
│   ├── api/          # All routers & endpoints
│   ├── core/         # Config, security, dependencies
│   ├── crud/         # CRUD operations
│   ├── models/       # SQLAlchemy models
│   ├── schemas/      # Pydantic schemas
│   ├── main.py       # FastAPI app instance
│   └── database.py   # DB session & engine
├── migrations/       # Alembic migrations
├── tests/            # pytest tests
├── .env.example
├── requirements.txt
├── docker-compose.yml
└── README.md

🤝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

👨‍💻 Author

Your Name – @yosefalemu

⭐ Show your support

Give a ⭐️ if this project helped you!


Made with ❤️ using FastAPI

Metadata

Release files for ada-backend 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ada-backend 0.1.0
File Size Uploaded Provenance Actions
ada_backend-0.1.0.tar.gz 3.0 kB Without provenance Details for ada_backend-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ada-backend 0.1.0
File Interpreter ABI Platform Actions
ada_backend-0.1.0-py3-none-any.whl Python 3 none any Details for ada_backend-0.1.0-py3-none-any.whl

Total release size: 6.2 kB

Release files / ada_backend-0.1.0.tar.gz

Download URL ada_backend-0.1.0.tar.gz
Size 3.0 kB
Tags Source
SHA-256 checksum
How to use checksums
fcc87eb9d5a96dbaccd3f90886b8eb0d4dc4d66c3e9af15c9e390ea5a29fc0ac
BLAKE2b-256 checksum
How to use checksums
7d9ec9f3a715a203d52851b2dae064d8c66b2992ae12c565550990aea9e3f488
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Pop!_OS","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / ada_backend-0.1.0-py3-none-any.whl

Download URL ada_backend-0.1.0-py3-none-any.whl
Size 3.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
66e9f087508b9aa20e68d397e34f92cc9df0e5545d5d6d9d2c71dd56bff475d9
BLAKE2b-256 checksum
How to use checksums
2b4b1c376f0b32f6fb8ea568d83bb5203648990385cf28aaaf1eab6e17784d8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Pop!_OS","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for ada-backend 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page