Skip to content

A modern web API built with Robyn (Python web framework written in Rust) featuring user management with CockroachDB database integration.

License

Notifications You must be signed in to change notification settings

derder3010/robyn-web-api

Repository files navigation

Robyn Web API

A modern web API built with Robyn (Python web framework written in Rust) featuring user management with CockroachDB database integration.

Features

  • ✅ JWT Authentication (Add your implementation details)
  • ✅ User CRUD operations
  • Pydantic request/response validation
  • SQLAlchemy ORM with Alembic migrations
  • ✅ CockroachDB database support
  • ✅ Environment configuration with .env
  • ✅ Hot reload during development

Installation

  1. Clone the repository
git clone https://github.com/yourusername/your-repo.git
cd your-repo
  1. Set up virtual environment
python -m venv .venv
source .venv/bin/activate  # Linux/MacOS
# .venv\Scripts\activate   # Windows
  1. Install dependencies
pip install -r requirements.txt
  1. Environment Setup
cp .env.example .env
# Update .env with your database credentials

Usage

  • Development Server
python -m robyn src/main.py --dev
  • --dev enables hot reload on file changes

  • Server runs at http://localhost:8080

  • Example Requests
# 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/<user-uuid>
  • Deployment:
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.

docker compose up -d --build

Database Migration (Using Alembic)

  • Initial Setup
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:

alembic revision --autogenerate -m "Add new feature"
  1. Review generated migration file
  2. Apply changes:
alembic upgrade head

Configuration

Required environment variables (.env file):

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 for details

About

A modern web API built with Robyn (Python web framework written in Rust) featuring user management with CockroachDB database integration.

Topics

Resources

License

Stars

Watchers

Forks