Add your description here
Project description
FastAPI Freelance Backend Template
This repository is a reusable FastAPI backend template for a freelancing platform. It includes:
- FastAPI with async endpoints
- PostgreSQL with SQLAlchemy 2.0 async sessions
- JWT authentication for users
- A
fastapi-readyCLI to scaffold new projects from this template - GitHub Actions workflows for CI and PyPI publishing with OIDC trusted publishing
- Python 3.8 support for local development, CI, and packaging
For Users of This Template
If you've installed this package with pip install fastapi-ready, go to "Create a New Project" section below.
If you've cloned or downloaded this repository to develop or modify the template itself, see "For Template Developers" at the end.
Quick Start
Install the template command with pip:
python -m pip install .
Install dependencies:
uv sync
Run the app:
uvicorn main:app --reload
Create a New Project
After installing this package, generate a fresh clean project from the template:
fastapi-ready directory_name
cd directory_name
uv sync
uvicorn main:app --reload
The generated project includes only the app scaffold and template files. It does not copy virtualenvs, installed libraries, or build artifacts.
After you run uv sync, a local .venv/ folder will appear in the new project. That is expected and comes from the environment install step, not from the template copy.
Usage pattern:
fastapi-ready my-new-appcreates a new folder in the current directoryfastapi-ready /absolute/path/to/my-new-appcreates the project at that pathfastapi-ready .is not supported because the current directory already exists
Environment Variables
Create a .env file in the project root:
DATABASE_URL=postgresql+asyncpg://postgres:root@localhost:5432/users
SECRET_KEY=your-secret-key
ACCESS_TOKEN_EXPIRE_MINUTES=60
SQL_ECHO=False
JWT_ALGORITHM=HS256
CI
The repository includes a GitHub Actions workflow that installs dependencies and runs checks on every push and pull request.
CD to PyPI
Publishing uses GitHub Actions OpenID Connect trusted publishing through PyPI.
When configuring the PyPI trusted publisher, use these values:
- PyPI project name:
project name - Owner:
owner - Repository name:
repository - Workflow name:
workflow.yml - Environment name:
pypi
The publishing workflow lives at .github/workflows/workflow.yml.
Files
.github/workflows/ci.yml- test workflow.github/workflows/workflow.yml- PyPI publish workflow
Versioning
Release versions are published from pyproject.toml. Bump the version before each PyPI release to avoid file reuse errors.
Helper Tools
Verify Scaffold Cleanliness
Use verify_scaffold.py to ensure a generated project contains only expected files:
python verify_scaffold.py /path/to/generated/project
This checks for:
- Correct top-level files (
.env.example,main.py, module directories) - No forbidden patterns (
.venv,__pycache__,.egg-info, etc.) - File and directory counts
Example output:
โ
Scaffold verification passed!
๐ Statistics:
Files: 12
Directories: 7
Generated Project Structure
When you run fastapi-ready my-app, the generated project includes:
my-app/
โโโ .env.example # Template environment variables
โโโ main.py # FastAPI application entry point
โโโ auth/ # Authentication module
โ โโโ auth.py # JWT & password utilities
โโโ config/ # Configuration module
โ โโโ __init__.py
โ โโโ settings.py # Environment-based settings
โโโ core/ # Core utilities
โ โโโ deps.py # Dependency injection
โโโ db/ # Database module
โ โโโ __init__.py
โ โโโ database.py # SQLAlchemy async setup
โโโ models/ # Database models
โ โโโ users.py # User model
โโโ router/ # API routes
โ โโโ __init__.py
โ โโโ auth.py # Auth endpoints
โโโ schemas/ # Pydantic schemas
โโโ users.py # User request/response schemas
First Steps After Generation
-
Create environment file:
cp .env.example .env
Update with your database URL, secret key, and other settings.
-
Install dependencies:
uv syncThis creates a
.venv/folder locally (not copied from the template). -
Run the app:
uvicorn main:app --reload
The dev server will start at
http://localhost:8000 -
Verify setup:
Visit
http://localhost:8000/docsfor interactive API documentation.
Environment Variables
The generated project requires these environment variables (create a .env file):
# Database (PostgreSQL + asyncpg)
DATABASE_URL=postgresql+asyncpg://user:password@localhost:5432/db_name
# Security
SECRET_KEY=your-secret-key-here-change-in-production
JWT_ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=60
# Database logging
SQL_ECHO=false
All variables are required; the app will fail to start if any are missing or empty.
Database Setup
The generated project uses SQLAlchemy 2.0 with async/await:
# Create PostgreSQL database
createdb fastapi_db
# Export connection string
export DATABASE_URL=postgresql+asyncpg://postgres:password@localhost:5432/fastapi_db
# Tables are created automatically on first app startup
Authentication Flow
The generated project includes JWT-based authentication:
- Register:
POST /auth/register- Create a new user (password hashed with bcrypt) - Login:
POST /auth/login- Get JWT token (valid for 60 min by default) - Protected endpoints: Include
Authorization: Bearer <token>header
Example:
# Register
curl -X POST http://localhost:8000/auth/register \
-H "Content-Type: application/json" \
-d '{"email": "user@example.com", "password": "secure123"}'
# Login
curl -X POST http://localhost:8000/auth/login \
-d "username=user@example.com&password=secure123"
For Template Developers
This section is for developers who want to modify, test, or publish this template package.
Local Development
git clone <repo>
cd backend
uv sync
uvicorn main:app --reload
Testing Template Generation
After making changes to the template:
# Reinstall the package in editable mode
uv pip install -e . --no-deps
# Generate a test scaffold
fastapi-ready /tmp/test-app
# Verify the scaffold
python verify_scaffold.py /tmp/test-app
Publishing to PyPI
- Update version in
pyproject.toml - Commit and tag:
git add . git commit -m "Release v0.2.0" git tag v0.2.0 git push origin main --tags
- Trigger workflow: Push to
mainwith a new version tag - Monitor: Check GitHub Actions for build/publish status
The workflow automatically publishes to PyPI using OIDC trusted publishing (no API tokens needed).
Project Structure
fastapi_ready.py- Template generator CLI (entry point)verify_scaffold.py- Scaffold validation toolmain.py,auth/,config/, etc. - Template scaffold files.github/workflows/- CI/CD pipelines
Adding New Template Files
- Create the file/directory in this repo
- Add the path to
INCLUDED_PATHSinfastapi_ready.py - Update
EXPECTED_SCAFFOLD_FILESinverify_scaffold.py - Test with:
fastapi-ready test-proj && python verify_scaffold.py test-proj
Project details
Release history Release notifications | RSS feed
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 fastapi_ready-0.1.2.tar.gz.
File metadata
- Download URL: fastapi_ready-0.1.2.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f1f29814e2918629b46d8cb0cb1710393544f703d46598dcf8afe80d3ea04b96
|
|
| MD5 |
363da14cca502a1496d9ff08519763bf
|
|
| BLAKE2b-256 |
7fc12705b956dda7f06cf6646dd2ce5353b5b5171c987d91246fa3ce68203d5f
|
Provenance
The following attestation bundles were made for fastapi_ready-0.1.2.tar.gz:
Publisher:
workflow.yml on Sachinn-p/fastapi-ready
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastapi_ready-0.1.2.tar.gz -
Subject digest:
f1f29814e2918629b46d8cb0cb1710393544f703d46598dcf8afe80d3ea04b96 - Sigstore transparency entry: 1358941186
- Sigstore integration time:
-
Permalink:
Sachinn-p/fastapi-ready@00aec7611fe9b6f4f06dd923c020e118352f2509 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Sachinn-p
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@00aec7611fe9b6f4f06dd923c020e118352f2509 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file fastapi_ready-0.1.2-py3-none-any.whl.
File metadata
- Download URL: fastapi_ready-0.1.2-py3-none-any.whl
- Upload date:
- Size: 9.2 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 |
99dfcc3a7a60f7076d16401b972033102e0986994abd3ad40494289795196b38
|
|
| MD5 |
233f1d6f01b4fe401461d7519f32522a
|
|
| BLAKE2b-256 |
31078c2186f445962c3620dddb05d79d972332a15475c39382a1d8e914e73b18
|
Provenance
The following attestation bundles were made for fastapi_ready-0.1.2-py3-none-any.whl:
Publisher:
workflow.yml on Sachinn-p/fastapi-ready
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastapi_ready-0.1.2-py3-none-any.whl -
Subject digest:
99dfcc3a7a60f7076d16401b972033102e0986994abd3ad40494289795196b38 - Sigstore transparency entry: 1358941192
- Sigstore integration time:
-
Permalink:
Sachinn-p/fastapi-ready@00aec7611fe9b6f4f06dd923c020e118352f2509 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Sachinn-p
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@00aec7611fe9b6f4f06dd923c020e118352f2509 -
Trigger Event:
workflow_dispatch
-
Statement type: