https://github.com/guduchango/sanic-python-example
sanic framework, migration, seed, docker-compose
https://github.com/guduchango/sanic-python-example
docker docker-compose mysql python sanic-framework
Last synced: 2 months ago
JSON representation
sanic framework, migration, seed, docker-compose
- Host: GitHub
- URL: https://github.com/guduchango/sanic-python-example
- Owner: guduchango
- Created: 2024-12-24T13:21:02.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-12-24T18:17:58.000Z (over 1 year ago)
- Last Synced: 2025-03-15T13:12:19.702Z (over 1 year ago)
- Topics: docker, docker-compose, mysql, python, sanic-framework
- Language: Python
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# π Sanic CRUD API Example
A simple CRUD API built with [Sanic](https://sanic.dev/) for practicing the basics of building high-performance web APIs in Python. This project includes a modular structure with controllers, models, database seeding, and runs easily with Docker.
Ideal for developers looking to explore Sanicβs asynchronous capabilities, request handling, and best practices for structuring a web API.
---
## π¦ Features
β
Fully asynchronous API with Sanic
β
CRUD endpoints for a single entity (`Item`)
β
Modular structure with controllers and models
β
Database migration and seed scripts
β
Docker & Docker Compose support for easy setup
β
Ready-to-use environment for experimenting with Sanic
---
## ποΈ Project Structure
.
βββ app/
β βββ controllers/ # Route handlers (controllers)
β βββ models/ # Database models
β βββ seeds/ # Seed scripts for database population
β βββ main.py # Entry point for the Sanic app
βββ database/
β βββ migrate.py # Migration script
β βββ seed.py # Seed script
βββ Dockerfile # Docker image definition
βββ docker-compose.yml # Docker Compose services configuration
βββ requirements.txt # Python dependencies
βββ README.md # Project documentation
---
## π Getting Started
### Clone the repository
```bash
git clone https://github.com/guduchango/sanic-python-example.git
cd sanic-python-example
```
---
## π³ Running with Docker
Build the Docker image:
```bash
docker-compose build
```
Start the containers:
```bash
docker-compose up
```
---
## π οΈ Database Migrations & Seeding
Run database migrations:
```bash
docker-compose run web python database/migrate.py
```
Seed the database with initial data:
```bash
docker-compose run web python database/seed.py
```
---
## π API Endpoints
Once the app is running on **http://localhost:8000**, the following CRUD routes are available:
| Method | Route | Description |
|--------|-----------------------|---------------------------|
| GET | `/` | Health check/test route |
| GET | `/items` | List all items |
| GET | `/items/` | Retrieve an item by ID |
| POST | `/items` | Create a new item |
| PUT | `/items/` | Update an existing item |
| DELETE | `/items/` | Delete an existing item |
---
## β
Example Requests with curl
**List all items**
```bash
curl -X GET http://localhost:8000/items
```
**Get a specific item**
```bash
curl -X GET http://localhost:8000/items/1
```
**Create a new item**
```bash
curl -X POST http://localhost:8000/items -H "Content-Type: application/json" -d '{"name": "New Item", "description": "A new item added to the database"}'
```
**Update an item**
```bash
curl -X PUT http://localhost:8000/items/1 -H "Content-Type: application/json" -d '{"name": "Updated Item", "description": "Updated description"}'
```
**Delete an item**
```bash
curl -X DELETE http://localhost:8000/items/1
```
---
## π Access the API
Once running, your API will be available at:
```
http://localhost:8000
```
---
## π Prerequisites
- Docker
- Docker Compose
---
## π License
MIT License.
---
## π Contributing
Contributions are welcome! Feel free to fork the repo and submit a pull request.