GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - heinrich10/pyfastapi: Simple backend example using Python and FastAPI

BranchesTags
Open more actions menu

Latest commit

 

History

37 Commits
37 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
alembic
alembic
 
 
http
http
 
 
pyfastapi
pyfastapi
 
 
tests
tests
 
 
.env.example
.env.example
 
 
.env.test
.env.test
 
 
.flake8
.flake8
 
 
.gitignore
.gitignore
 
 
.python-version
.python-version
 
 
AGENTS.md
AGENTS.md
 
 
Dockerfile
Dockerfile
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
alembic.ini
alembic.ini
 
 
pyproject.toml
pyproject.toml
 
 
run.py
run.py
 
 
uv.lock
uv.lock
 
 

Repository files navigation

PYFASTAPI

Sample backend API built with FastAPI, SQLAlchemy 2.x, and Alembic. It demonstrates a layered architecture with full CRUD endpoints for Person and read-only list/detail endpoints for Country and Continent.

Pre-requisites

  • Python 3.12+
  • uv
  • SQLite

How to run

  1. Install dependencies
    uv sync --locked --all-extras --dev

  2. Copy .env.example to .env and change the values if needed
    cp .env.example .env

  3. Run the app
    uv run python run.py

  4. Call the API endpoint
    curl http://localhost:5000/persons

  5. Open http://localhost:5000/docs to view the OpenAPI docs

How to run in a container

  1. Build the image
    docker build -t pyfastapi .

  2. Run the image
    docker run -p 5000:5000 pyfastapi

Note: You can use podman instead of docker as it is a drop-in replacement.

Seed Data

  1. Run migrations
    alembic upgrade head

  2. The SQL schema and seed data will be created in ./sql_app.db

  3. The database URL is read from .env (or .env.test when ENVIRONMENT=test) via pyfastapi/utils/config.py and passed to Alembic in alembic/env.py. alembic.ini is used for other Alembic settings.

Tests

  1. Make sure dependencies are installed
    uv sync --locked --all-extras --dev

  2. Run the test suite
    uv run pytest

  3. Run with coverage
    uv run poe coverage

Tests automatically set ENVIRONMENT=test, which loads .env.test for test configuration.

API Conventions

  • No trailing slashes on collection endpoints. Routes are registered as /persons, /countries, and /continents. Accessing the trailing-slash variant (e.g., /persons/) will receive a 307 Temporary Redirect to the canonical path.
  • Sort syntax ( /persons and /countries only): Prefix with - for descending (e.g., -name), + or no prefix for ascending.
  • Filter syntax (/persons and /countries only): Query parameters are mapped to schema fields. String fields use ILIKE (%value%); others use exact equality.
  • GET /continents returns a plain List[ContinentSchema]; it is not paginated and does not support sort/filter parameters.
  • POST /persons creates a person and returns PersonListSchema (which includes country_code but not the nested country/continent).
  • PUT /persons/{id} is an upsert. If the ID exists it is updated; if it does not exist a new person is created with that ID. Returns 204 No Content.
  • DELETE /persons/{id} removes the person and returns 204 No Content. Returns 404 Not Found if the person does not exist.

Data Model

---
config:
  layout: dagre
  look: handDrawn
title: ERD
---
erDiagram
    persons {
        int id PK
        String last_name "nullable"
        String first_name
        String country_code FK
    }
    countries {
        String code PK
        String name
        int phone
        String symbol "nullable"
        String capital "nullable"
        String currency "nullable"
        String continent_code FK "nullable"
        String alpha_3 "nullable"
    }
    continents {
        String code PK
        String name
    }
    persons }|--|| countries : "country"
    countries }|--|| continents : "continent"
Loading

About

Simple backend example using Python and FastAPI

Topics

fastapipythonsqlalchemysqlite

Resources

Readme
MIT license
Activity

Stars

0 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.