A modern web API built with Robyn (Python web framework written in Rust) featuring user management with CockroachDB database integration.
- ✅ 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
- Clone the repository
git clone https://github.com/yourusername/your-repo.git
cd your-repo
- Set up virtual environment
python -m venv .venv
source .venv/bin/activate # Linux/MacOS
# .venv\Scripts\activate # Windows
- Install dependencies
pip install -r requirements.txt
- Environment Setup
cp .env.example .env
# Update .env with your database credentials
- 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
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
- Initial Setup
alembic init alembic
Migration Commands:
alembic revision --autogenerate -m "message"
- Create new migrationalembic upgrade head
- Apply pending migrationsalembic downgrade -1
- Rollback last migrationalembic current
- Show current revisionalembic history
- Show migration history
-
Modify SQLAlchemy models in
src/models.py
-
Generate migration:
alembic revision --autogenerate -m "Add new feature"
- Review generated migration file
- Apply changes:
alembic upgrade head
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
MIT License - see LICENSE for details