If you're a developer looking to create robust web applications with FastAPI, you know how vital it is to start with a solid foundation. The FastAPI template from s3rius provides a feature-rich and configurable starting point for building your APIs, whether you're working on a small project or a large-scale application. This template simplifies many of the repetitive tasks associated with setting up a new FastAPI project, allowing you to focus on what truly matters: building great features.
What Is FastAPI Template?
FastAPI Template is a highly configurable project template designed for developers who want to kickstart their FastAPI applications quickly and efficiently. Built with flexibility in mind, it supports various databases, ORMs, and other essential tools that modern applications often require. This project is perfect for both beginners who want to get up and running with FastAPI and experienced developers looking for a robust starting point for their applications.
Key Features
- Highly Configurable: Choose between different databases (like PostgreSQL, SQLite, etc.) and ORMs (like SQLAlchemy, TortoiseORM, Beanie, and more) to suit your project needs.
- Pydantic V2 Support: Benefit from the latest features of Pydantic, improving data validation and settings management.
- GraphQL and REST API Options: Easily select your preferred API style, allowing you to serve clients with different needs.
- Built-in Testing: Automatically generated tests with approximately 90% coverage ensure that your code is robust and reliable.
- Optional Integrations: Enhance your application with Prometheus for monitoring, Sentry for error tracking, and Opentelemetry for observability.
- Docker Support: Quickly deploy your application within a Docker container, simplifying the development and deployment process.
- Pre-commit Integration: Ensure code quality with pre-commit hooks to automate checks before code submissions.
- Task Management: Integrate with Taskiq for handling background tasks efficiently.
Installation & Setup
Getting started with the FastAPI template is straightforward. Before you begin, make sure you have Git, Python, and UV installed on your machine. Here are the steps to install it:
python3 -m pip install fastapi_template
python3 -m fastapi_template
# or simply run fastapi_template
# Answer the prompts to configure your project
cd new_project
docker-compose up --build
If you prefer to install from source, you can do so with the following commands:
python3 -m pip install uv
python3 -m pip install .
python3 -m fastapi_template
For a Docker-based setup, use the following command:
docker run --rm -it -v "$(pwd):/projects" ghcr.io/s3rius/fastapi_template
How to Use It
Let’s walk through a practical example of creating a new FastAPI project using the template. Once you’ve installed the template, you can generate a new project by answering a series of configuration questions. Here’s how it looks:
python3 -m fastapi_template
After you’ve created your project, navigate to the project directory:
cd new_project
You can now run your FastAPI application using Uvicorn:
uvicorn app.main:app --reload
With your application running, you can access it at http://127.0.0.1:8000. Enjoy exploring the auto-generated documentation at http://127.0.0.1:8000/docs!
Who Should Use FastAPI Template?
The FastAPI Template is ideal for a wide range of developers. If you're a beginner, it provides a guided setup that helps you learn the fundamentals of FastAPI while building a functional project. For seasoned developers, its flexibility and extensive feature set save time, allowing you to focus on building unique aspects of your application rather than repetitive setup tasks. Whether you're creating a small API for a personal project or a complex microservices architecture, this template can help streamline your workflow.
Final Thoughts
In a landscape where rapid development is crucial, the FastAPI Template stands out as a powerful tool. It offers a combination of flexibility, modern features, and ease of use that caters to developers at all levels. With its robust set of integrations and support for different technologies, you can quickly build and deploy applications that meet today's demands. If you're looking to kickstart your next FastAPI project, give this template a try. It might just become your go-to starting point for future applications.