https://github.com/derder3010/robyn-web-api
A modern web API built with Robyn (Python web framework written in Rust) featuring user management with CockroachDB database integration.
https://github.com/derder3010/robyn-web-api
backend docker pydantic python robyn sqlalchemy
Last synced: about 2 months ago
JSON representation
A modern web API built with Robyn (Python web framework written in Rust) featuring user management with CockroachDB database integration.
- Host: GitHub
- URL: https://github.com/derder3010/robyn-web-api
- Owner: derder3010
- License: mit
- Created: 2025-01-24T11:44:47.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-28T07:30:13.000Z (over 1 year ago)
- Last Synced: 2025-07-02T01:36:29.005Z (12 months ago)
- Topics: backend, docker, pydantic, python, robyn, sqlalchemy
- Language: Python
- Homepage:
- Size: 33.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Robyn Web API
A modern web API built with [Robyn](https://robyn.tech/) (Python web framework written in **Rust**) featuring user management with [CockroachDB](https://github.com/cockroachdb/cockroach) database integration.
## Features
- ✅ JWT Authentication (Add your implementation details)
- ✅ User CRUD operations
- ✅ [Pydantic](https://docs.pydantic.dev) request/response validation
- ✅ [SQLAlchemy](https://www.sqlalchemy.org/) ORM with Alembic migrations
- ✅ CockroachDB database support
- ✅ Environment configuration with `.env`
- ✅ Hot reload during development
## Installation
1. **Clone the repository**
```bash
git clone https://github.com/yourusername/your-repo.git
cd your-repo
```
2. **Set up virtual environment**
```bash
python -m venv .venv
source .venv/bin/activate # Linux/MacOS
# .venv\Scripts\activate # Windows
```
3. **Install dependencies**
```bash
pip install -r requirements.txt
```
4. **Environment Setup**
```bash
cp .env.example .env
# Update .env with your database credentials
```
## Usage
- Development Server
```bash
python -m robyn src/main.py --dev
```
- `--dev` enables hot reload on file changes
- Server runs at `http://localhost:8080`
* Example Requests
```bash
# Create user
curl -X POST http://localhost:8080/user \
-H "Content-Type: application/json" \
-d '{"username": "testuser", "password": "secret"}'
# Get user
curl http://localhost:8080/user/
```
- Deployment:
```bash
python src/main.py --processes=n --workers=m
```
## Using with Docker
If you want to use this application with Docker, please ensure that you copy the `root.cert` file (downloaded from CockroachDB Cloud) into this directory. This certificate is required to establish a secure connection to the CockroachDB database.
```shell
docker compose up -d --build
```
## Database Migration (Using Alembic)
- Initial Setup
```bash
alembic init alembic
```
Migration Commands:
- `alembic revision --autogenerate -m "message"` - Create new migration
- `alembic upgrade head` - Apply pending migrations
- `alembic downgrade -1` - Rollback last migration
- `alembic current` - Show current revision
- `alembic history` - Show migration history
## Migration Workflow
1. Modify SQLAlchemy models in `src/models.py`
2. Generate migration:
```bash
alembic revision --autogenerate -m "Add new feature"
```
3. Review generated migration file
4. Apply changes:
```bash
alembic upgrade head
```
## Configuration
Required environment variables (`.env file`):
```ini
DATABASE_URL=cockroachdb://user:password@localhost/dbname
SECRET_KEY=your-secret-key-here
ACCESS_TOKEN_EXPIRE_MINUTES=30
```
Project Structure
```
.
├── src/
│ ├── main.py # Main application entry
│ ├── models.py # SQLAlchemy models
│ ├── schemas.py # Pydantic models
│ ├── handlers.py # Business logic
│ ├── routes.py # API endpoints
│ └── database/ # Database configuration
├── alembic/ # Migration scripts
├── .env.example # Environment template
├── requirements.txt # Dependencies
└── README.md # This file
```
## License
MIT License - see [LICENSE](https://github.com/derder3010/robyn-web-api/blob/main/LICENSE) for details