- Overview
- Features
- Technologies Used
- Getting Started
- Usage
- API Endpoints
- Testing
- Contributing
- License
- Acknowledgments
This repository, TemplatesFastAPI, offers a robust starter template for building applications with FastAPI. It includes features such as JWT authentication, MongoDB integration, and support for large language models (LLMs). This template provides a solid foundation for developers looking to create scalable and efficient RESTful APIs.
- FastAPI: High-performance web framework for building APIs.
- JWT Authentication: Secure user authentication and authorization.
- MongoDB: NoSQL database for storing application data.
- LLM Integration: Connect with large language models like OpenAI for enhanced functionality.
- Modular Structure: Organized codebase for easy navigation and maintenance.
- Environment Configuration: Simple setup with environment variables.
- API Documentation: Automatically generated using Swagger UI.
- Python 3: Programming language for backend development.
- FastAPI: Framework for building APIs quickly and efficiently.
- MongoDB: Database for storing data in a flexible, JSON-like format.
- Pydantic: Data validation and settings management using Python type annotations.
- PyJWT: JSON Web Token implementation for authentication.
- Uvicorn: ASGI server for running FastAPI applications.
- OpenAI API: Integration for leveraging language models.
Before you begin, ensure you have the following installed:
- Python 3.7 or higher
- MongoDB (local or cloud instance)
- Git
-
Clone the repository:
git clone https://github.com/Rony-Soc/TemplatesFastAPI.git cd TemplatesFastAPI -
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install the required packages:
pip install -r requirements.txt
-
Set up environment variables. Create a
.envfile in the root directory and add your configuration:MONGODB_URL=mongodb://localhost:27017 JWT_SECRET=your_jwt_secret OPENAI_API_KEY=your_openai_api_key
To start the FastAPI application, run:
uvicorn app.main:app --reloadYour application will be available at http://127.0.0.1:8000.
For the latest release, download the necessary files from the Releases section and execute them as needed.
Once the application is running, you can interact with it using tools like Postman or Curl. The API provides endpoints for user registration, login, and accessing protected resources.
To register a new user, send a POST request to /register with the following JSON body:
{
"username": "your_username",
"password": "your_password"
}To log in, send a POST request to /login with the same credentials:
{
"username": "your_username",
"password": "your_password"
}This will return a JWT token for authentication.
To access protected routes, include the JWT token in the Authorization header:
Authorization: Bearer your_jwt_token
| Method | Endpoint | Description |
|---|---|---|
| POST | /register |
Register a new user |
| POST | /login |
Authenticate user |
| GET | /protected |
Access protected resource |
| POST | /llm-query |
Query the LLM with user input |
To run the tests, ensure your virtual environment is activated and run:
pytest tests/This will execute all tests in the tests directory.
Contributions are welcome! If you have suggestions or improvements, please fork the repository and submit a pull request. Ensure your code adheres to the existing style and includes appropriate tests.
- Fork the repository.
- Create a new branch:
git checkout -b feature/YourFeature. - Make your changes and commit them:
git commit -m 'Add some feature'. - Push to the branch:
git push origin feature/YourFeature. - Open a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
- Thanks to the FastAPI community for their excellent framework.
- Special thanks to the developers of the libraries used in this project.
- Inspiration from various open-source projects that paved the way for this template.
For more details, visit the Releases section.