Sergo
Note: Sergo is a very new framework and is still in its early stages of development. It may contain bugs and limitations. The framework will evolve and improve as I build applications on top of it. Expect frequent updates and potentially breaking changes as the project matures.
Sergo is a lightweight, flexible Python web framework inspired by Django, designed for building serverless web APIs quickly and efficiently. It provides a set of tools and abstractions that make it easy to create scalable and cheap web applications.
Current Support
Database Engines:
- PostgreSQL (via
sergo.connection.postgres.PostgresConnection) — psycopg v3 - SQLite (via
sergo.connection.sqlite.SQLiteConnection) - Azure SQL / Transact-SQL (via
sergo.connection.transactql.AzureSQLConnection)
Query Engines:
- PostgreSQL (via
sergo.query.postgres.PostgresQuery) - SQLite (via
sergo.query.sqlite.SQLiteQuery) - Transact-SQL (via
sergo.query.transactql.TransactSQLQuery)
Handlers:
- FastAPI (via
sergo.handler.FastAPIHandler) - Azure Functions (via
sergo.handler.AzureFunctionHandler)
Background Tasks:
- TaskLoop — fire-and-forget tasks + recurring background loops
Quick Start
-
Setup venv
mkdir my_project && cd my_project python -m venv venv source venv/bin/activate -
Install Sergo:
pip install git+https://github.com/Somers1/sergo.git -
Create a new Sergo project:
sergo-admin startapp -
Define your models (
models/models.py):from sergo.model import Model from sergo import fields class User(Model): id = fields.IDField() name = fields.StringField() email = fields.StringField() class Meta: db_table = 'users'
-
Create serializers (
serializers/serializers.py):from models import models from sergo.serializer import Serializer class UserSerializer(Serializer): model_class = models.User fields = ['__all__']
-
Define views (
views/views.py):from models import models from serializers import serializers from sergo.viewset import ViewSet class UserViewSet(ViewSet): methods = ['GET', 'POST', 'PATCH', 'DELETE'] model_class = models.User serializer_class = serializers.UserSerializer filter_fields = ('id', 'name') search_fields = ('name',)
-
Set up URL patterns (
urls/urls.py):from views import views urlpatterns = { '/api/user': views.UserViewSet, }
-
Run:
python runserver.py
Background Tasks
Sergo includes a TaskLoop for running background work in the same asyncio event loop as your FastAPI server. No external dependencies (no Celery, no Redis).
Setup
# runserver.py
from sergo.handler import get_handler
from sergo.tasks import TaskLoop
loop = TaskLoop()
# Register recurring background jobs
@loop.recurring(interval=60)
async def check_reminders():
"""Runs every 60 seconds."""
due = get_due_reminders()
for r in due:
loop.add_task(process_reminder(r))
@loop.recurring(interval=900, name="heartbeat")
async def heartbeat():
"""Runs every 15 minutes."""
await do_heartbeat_check()
# TaskLoop starts/stops automatically with the server
handler = get_handler()
handler.configure(task_loop=loop)
Fire-and-Forget Tasks
Queue async work from anywhere — views, background jobs, wherever. The task runs in the background without blocking the response.
# views/views.py
from runserver import loop
class NotificationViewSet(ViewSet):
methods = ['POST']
model_class = models.Notification
def handle_post(self, request):
notif = super().handle_post(request)
# Process async without blocking the HTTP response
loop.add_task(process_notification(request.body))
return notif
How It Works
Everything runs in a single asyncio event loop:
Event Loop
├── uvicorn (HTTP requests)
├── task consumer (fire-and-forget queue)
├── recurring job 1 (e.g. every 60s)
├── recurring job 2 (e.g. every 900s)
└── any awaited calls (LLM, external APIs, etc.)
All tasks cooperate via await. Recurring loops sleep between runs without blocking. Fire-and-forget tasks are queued and executed concurrently. Errors are logged but never crash the server.
Configuration
Sergo uses TOML files for configuration. Create a system.toml file in your project root:
[global]
timezone = "UTC"
[sergo]
handler_engine = "sergo.handler.FastAPIHandler"
database_engine = "sergo.connection.postgres.PostgresConnection"
query_engine = "sergo.query.postgres.PostgresQuery"
log_level = "INFO"
[database]
host = "localhost"
name = "mydb"
user = "postgres"
pass = ""
port = 5432
SQLite Configuration
[sergo]
database_engine = "sergo.connection.sqlite.SQLiteConnection"
query_engine = "sergo.query.sqlite.SQLiteQuery"
[database]
path = "/path/to/db.sqlite"
Database Migrations
Sergo does not handle database migrations automatically. You are responsible for managing your database schema. Recommendations:
- Use SQL scripts to manage schema changes
- Use Alembic for automated migrations
- Implement a custom migration system
Contributing
We welcome contributions!
License
Sergo is released under the MIT License.
Metadata
Release files for sergo 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| sergo-0.1.0.tar.gz | 38.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sergo-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 80.4 kB
Release files / sergo-0.1.0.tar.gz
| Download URL | sergo-0.1.0.tar.gz |
|---|---|
| Size | 38.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6422e7df6b9303d253d6b9f722bc321907bbd33fb91b5e982e44c703191f862a
|
|
BLAKE2b-256 checksum How to use checksums |
5b790ec0e3fbc167d55cc856168a9c13d4b2e496931748b71bfac994752c8ffb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.9
|
Release files / sergo-0.1.0-py3-none-any.whl
| Download URL | sergo-0.1.0-py3-none-any.whl |
|---|---|
| Size | 41.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
68aa948c6a3e725719fed428f11924f5bafd1f547ae25ecd80cede6144ef2afc
|
|
BLAKE2b-256 checksum How to use checksums |
aef1b545870d8582dd67c5ed943d2db0f7196c79245244280b86e18f276edd80
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.9
|
Security for sergo 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.