Skip to content

eugeneliukindev/FastAPI-Starter-Kit

Repository files navigation

FastAPI Starter Kit 🚀

A lightweight, ready-to-use template for building APIs with FastAPI. Get started in minutes without the hassle of complex setup!

Why Use This Starter Kit?

This template is designed to streamline your FastAPI development by eliminating:

  • 🛠️ Database configuration
  • ⚙️ Environment setup
  • 📂 Tedious project initialization and structure
  • 🗂️ Manual setup of SQLAlchemy models and Pydantic schemas

Features

  • Type safety with Mypy support
  • 🧹 Code quality ensured by Ruff linter and formatter
  • 📦 Dependency management via Poetry
  • 🗄️ Asynchronous SQLAlchemy with AsyncPG driver for high-performance work with PostgreSQL
  • 🐳 Dockerized Postgres for quick database setup
  • 🔄 Alembic migrations for seamless database schema management

Getting Started

Follow these steps to set up and run the project locally.

Prerequisites

  • 🐍 Python 3.12+
  • 📦 Poetry for dependency management
  • 🐳 Docker (optional, for Postgres setup)

Installation

  1. Clone the Repository

    Using HTTPS:

    git clone https://github.com/eugeneliukindev/FastAPI-Starter-Kit.git

    Using SSH (recommended):

    git clone [email protected]:eugeneliukindev/FastAPI-Starter-Kit.git
  2. Install Dependencies

    This project uses Poetry for dependency management. See pyproject.toml for details.

    Optional: Configure Poetry to create a virtual environment in the project root:

    poetry config virtualenvs.in-project true

    Install dependencies:

    With dev dependencies (for development):

    poetry install

    Without dev dependencies (for production):

    poetry install --without dev
  3. Set Up the Database

    Use the provided Docker Compose file to spin up a Postgres database:

    docker compose up -d

    Note: Ensure Docker is installed and running.

  4. Run Alembic Migrations

    Apply an existing database migration using Alembic:

    alembic upgrade head
  5. Start the Application

    Run the FastAPI server:

    python main.py

    Your API is now running! Access it at http://localhost:8000 (or the configured port).

Usage

  • 📚 API Documentation: Auto-generated by FastAPI at /docs (Swagger UI) or /redoc
  • 🛠️ Development Tools:
    • Run mypy . for type checking
    • Run ruff check . for linting
    • Run ruff format . for code formatting

Additional Notes

  • Important Note About .env

    The .env file is used to store sensitive data like database credentials. For demonstration purposes, it's not included in .gitignore. For security reasons, we strongly recommend adding .env to .gitignore to prevent accidentally committing sensitive data to the repository:

    echo ".env" >> .gitignore
  • Initializing pre-commit Hooks

    If you installed dev dependencies via poetry install, pre-commit was included in the installation. To activate it, run:

    pre-commit install

Contributing

Contributions are welcome! Please:

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

License

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


Happy coding! 🎉 If you have questions or need help, feel free to open an issue.

About

Starter template for creating API on FastAPI!

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published