A lightweight, high-performance API boilerplate built with the Sanic framework.
This boilerplate provides a minimal setup for creating a REST API using the Sanic framework. Sanic is an async Python web server that's built to be fast, simple, and easy to use.
Sanic allows for asynchronous request handling, making it ideal for I/O-bound applications that require high throughput.
Documentation: https://sanic.dev/en/#production-ready
- Asynchronous request handling
- Simple CRUD API structure
- CORS middleware configuration
- Easy to extend and customize
- Minimal dependencies
- Type hints and modern Python practices
- Python - Programming language
- Sanic - Web framework
- Sanic-CORS - CORS handling
- Python 3.7+
- pip (Python package manager)
You can use any of the following methods to set up your environment:
# Create a virtual environment
python -m venv venv
# Activate the virtual environment
# On Windows
venv\Scripts\activate
# On macOS/Linux
source venv/bin/activate# Create a conda environment
conda create -n sanic-boilerplate python=3.9
# Activate the environment
conda activate sanic-boilerplateInstall the dependencies using pip:
pip install -r requirements.txt-
To add new requirements:
- Add the package name to
requirements.txt - Run
pip install -r requirements.txt
- Add the package name to
-
Alternatively, install directly and update requirements:
pip install package-name pip freeze > requirements.txt
python main.pyThe server will start on http://localhost:8000.
sanic-boilerplate/
├── main.py # Main application file with route definitions
├── requirements.txt # Project dependencies
└── README.md # Project documentation
GET /ping- Health check endpointGET /api/items- Get all itemsPOST /api/items- Create a new itemPUT /api/items/:id- Update an itemDELETE /api/items/:id- Delete an item
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
If you have any questions or run into issues, please:
- Check the Sanic documentation
- Open an issue in this repository
Happy coding! 🎉