Skip to main content

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

  1. Install the package in development mode:

    pip install -e .
    
  2. Run the application:

    uvicorn src.fastapi_todo_list.main:app --reload
    
  3. Access the API documentation:

API Endpoints

  • GET / - Welcome message with endpoint overview
  • GET /todos - Get all active todos
  • GET /todos/completed - Get completed todos
  • GET /todos/all - Get all todos
  • GET /todos/{id} - Get specific todo
  • POST /todos - Create new todo
  • PUT /todos/{id} - Update existing todo
  • DELETE /todos/{id} - Delete todo

Testing

Run the test suite:

python -m pytest tests/

Run API tests:

python test_api.py
  1. Access the API:

API Endpoints

Overview

  • GET / - Welcome message with endpoint overview

Todo Operations

  • GET /todos - Get all active (incomplete) todos
  • GET /todos/completed - Get all completed todos
  • GET /todos/all - Get all todos regardless of status
  • GET /todos/{id} - Get a specific todo by ID
  • POST /todos - Create a new todo
  • PUT /todos/{id} - Update an existing todo
  • DELETE /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 description
  • completed: Boolean completion status
  • created_at: Creation timestamp
  • updated_at: Last modification timestamp
  • completed_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:

These interfaces allow you to test all endpoints directly from your browser.

Development

To extend the application:

  1. Add new database models in database.py
  2. Create corresponding Pydantic schemas in schemas.py
  3. Implement CRUD operations in crud.py
  4. 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

todolist_fastapi-1.0.4.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

todolist_fastapi-1.0.4-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file todolist_fastapi-1.0.4.tar.gz.

File metadata

  • Download URL: todolist_fastapi-1.0.4.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

Hashes for todolist_fastapi-1.0.4.tar.gz
Algorithm Hash digest
SHA256 e28b1d49352040b5087a3409a29b0bfaf3cc817502667d0b145be0736e4fe564
MD5 47df556cda8aaa4fc3604b0826392d1a
BLAKE2b-256 a06eb10f8db0b9d592edbc9f1c5532533cd79bad3520dd758cf4985687f19e25

See more details on using hashes here.

Provenance

The following attestation bundles were made for todolist_fastapi-1.0.4.tar.gz:

Publisher: publish-fastapi-todo.yml on amalieshi/amalie_projects

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file todolist_fastapi-1.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for todolist_fastapi-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 0f0427cab7462b3b7f7aeeda23bce29f13f35c4241060af85f3b8345eec98977
MD5 39e5935f2536663490dbcc85086f34c2
BLAKE2b-256 0ee92c637ac13518b70a28b34fa7727899e69bfbfd81e8bf2c0ec72106d6ad05

See more details on using hashes here.

Provenance

The following attestation bundles were made for todolist_fastapi-1.0.4-py3-none-any.whl:

Publisher: publish-fastapi-todo.yml on amalieshi/amalie_projects

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page