A simple and efficient todo list API built with FastAPI
Project description
Todo API
A robust FastAPI-based todo list API with comprehensive CRUD operations, automatic timestamp tracking, and complete data validation.
Features
- Add todo items with title and optional description
- Mark items as completed with automatic completion timestamps
- Remove items from the list
- View active todos with creation and modification dates
- View completed todos with completion dates
- Update existing todos (title, description, status)
Project Structure
todo-api/
├── pyproject.toml # Project metadata and dependencies
├── README.md # Project documentation
├── test_api.py # API testing script
├── tests/ # Test suite
└── src/
└── fastapi_todo_list/
├── __init__.py # Package initialization
├── main.py # FastAPI application and API endpoints
├── database.py # Database setup and models
├── schemas.py # Pydantic models for request/response
├── crud.py # Database operations
└── config.py # Configuration settings
Technology Stack
- FastAPI: Modern, fast web framework for building APIs
- SQLAlchemy: SQL toolkit and ORM
- Pydantic: Data validation using Python type annotations
- SQLite: Lightweight database for development
- Uvicorn: ASGI web server implementation
- Pytest: Testing framework
Installation and Setup
-
Install the package in development mode:
pip install -e .
-
Run the application:
uvicorn src.fastapi_todo_list.main:app --reload
-
Access the API documentation:
- Interactive docs: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
API Endpoints
GET /- Welcome message with endpoint overviewGET /todos- Get all active todosGET /todos/completed- Get completed todosGET /todos/all- Get all todosGET /todos/{id}- Get specific todoPOST /todos- Create new todoPUT /todos/{id}- Update existing todoDELETE /todos/{id}- Delete todo
Testing
Run the test suite:
python -m pytest tests/
Run API tests:
python test_api.py
- Access the API:
- API: http://localhost:8000
- Interactive docs: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
API Endpoints
Overview
GET /- Welcome message with endpoint overview
Todo Operations
GET /todos- Get all active (incomplete) todosGET /todos/completed- Get all completed todosGET /todos/all- Get all todos regardless of statusGET /todos/{id}- Get a specific todo by IDPOST /todos- Create a new todoPUT /todos/{id}- Update an existing todoDELETE /todos/{id}- Delete a todo
Building & Distribution
Build the Package
# Install build tools
pip install build twine
# Build the package
python -m build
This creates distribution files in the dist/ directory:
fastapi_todo_list-1.0.0-py3-none-any.whl(wheel)fastapi_todo_list-1.0.0.tar.gz(source distribution)
Publish to Feed
Option 1: PyPI (Public Registry)
# Test PyPI (recommended first)
twine upload --repository testpypi dist/*
# Production PyPI
twine upload dist/*
Option 2: GitHub Packages
# Configure GitHub token first
# Then upload to GitHub Packages
twine upload --repository-url https://upload.pypi.org/legacy/ dist/*
Option 3: GitHub Releases
# Manual upload to: https://github.com/amalieshi/amalie_projects/releases
# Or use GitHub CLI:
gh release create v1.0.0 dist/* --title "FastAPI Todo List v1.0.0"
Option 4: Private Feed/Repository
# Azure DevOps, JFrog Artifactory, Nexus, etc.
twine upload --repository-url https://your-private-feed-url dist/*
Your GitHub Repository Feed URLs:
- Releases:
https://github.com/amalieshi/amalie_projects/releases - Repository:
https://github.com/amalieshi/amalie_projects.git - Package Directory:
python/web-frameworks/fastapi/
Development Tools
The project includes configuration for development tools:
# Code formatting with black
black src/
# Type checking with mypy
mypy src/
# Linting with flake8
flake8 src/
# Run tests
pytest
Usage Examples
Create a new todo
curl -X POST "http://localhost:8000/todos" \
-H "Content-Type: application/json" \
-d '{"title": "Buy groceries", "description": "Milk, bread, and eggs"}'
Get all active todos
curl "http://localhost:8000/todos"
Mark a todo as completed
curl -X PUT "http://localhost:8000/todos/1" \
-H "Content-Type: application/json" \
-d '{"completed": true}'
Get completed todos
curl "http://localhost:8000/todos/completed"
Delete a todo
curl -X DELETE "http://localhost:8000/todos/1"
Data Model
Each todo item contains:
id: Unique identifier (auto-generated)title: Todo title (required)description: Optional descriptioncompleted: Boolean completion statuscreated_at: Creation timestampupdated_at: Last modification timestampcompleted_at: Completion timestamp (null if not completed)
Database
The application uses SQLite with SQLAlchemy ORM for data persistence. The database file (todos.db) is created automatically when the application starts.
Interactive Documentation
FastAPI automatically generates interactive API documentation:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
These interfaces allow you to test all endpoints directly from your browser.
Development
To extend the application:
- Add new database models in
database.py - Create corresponding Pydantic schemas in
schemas.py - Implement CRUD operations in
crud.py - Add new endpoints in
main.py
Technologies Used
- FastAPI: Modern, fast web framework for building APIs
- SQLAlchemy: SQL toolkit and ORM
- Pydantic: Data validation using Python type hints
- SQLite: Lightweight database engine
- Uvicorn: ASGI server for running the application
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file todolist_fastapi-1.0.5.tar.gz.
File metadata
- Download URL: todolist_fastapi-1.0.5.tar.gz
- Upload date:
- Size: 12.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59450a69aa09e95f009988e4a44d518e56a9aa7d9dbb4d8eb1ebd87fcb00a613
|
|
| MD5 |
7f1f0d8632e27e4fcbed31b778053c65
|
|
| BLAKE2b-256 |
e9f8257fda346b657f818bb7e8604544f6661b796b9c0bc067c68f8efb55187c
|
Provenance
The following attestation bundles were made for todolist_fastapi-1.0.5.tar.gz:
Publisher:
publish-fastapi-todo.yml on amalieshi/amalie_projects
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
todolist_fastapi-1.0.5.tar.gz -
Subject digest:
59450a69aa09e95f009988e4a44d518e56a9aa7d9dbb4d8eb1ebd87fcb00a613 - Sigstore transparency entry: 1342771824
- Sigstore integration time:
-
Permalink:
amalieshi/amalie_projects@0b91a1c3833d2fd868f382301a46d3891cd169c3 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/amalieshi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-fastapi-todo.yml@0b91a1c3833d2fd868f382301a46d3891cd169c3 -
Trigger Event:
push
-
Statement type:
File details
Details for the file todolist_fastapi-1.0.5-py3-none-any.whl.
File metadata
- Download URL: todolist_fastapi-1.0.5-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc8a21d03f3204b9e3fb7ffeb9d81f413291baee806fa0aaa539086561cf6658
|
|
| MD5 |
ab943201f402ceb3f1d34196c2ddbec4
|
|
| BLAKE2b-256 |
c8e25083ee67547952eef06702b0f21b518bdc7ff22e9672ffe998ea5f4b8b9d
|
Provenance
The following attestation bundles were made for todolist_fastapi-1.0.5-py3-none-any.whl:
Publisher:
publish-fastapi-todo.yml on amalieshi/amalie_projects
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
todolist_fastapi-1.0.5-py3-none-any.whl -
Subject digest:
bc8a21d03f3204b9e3fb7ffeb9d81f413291baee806fa0aaa539086561cf6658 - Sigstore transparency entry: 1342771849
- Sigstore integration time:
-
Permalink:
amalieshi/amalie_projects@0b91a1c3833d2fd868f382301a46d3891cd169c3 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/amalieshi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-fastapi-todo.yml@0b91a1c3833d2fd868f382301a46d3891cd169c3 -
Trigger Event:
push
-
Statement type: