Introduction
rhosocial ActiveRecord
rhosocial ActiveRecord is a modern, Pythonic implementation of the ActiveRecord pattern, providing an elegant and intuitive interface for database operations with type safety and rich features.
Features
Modern Python Support
Pure Python implementation with no external ORM dependencies
Comprehensive type hints using modern Python features
Built with Python 3.10+ in mind
Pydantic integration for data validation
Type Safety
Strong type checking through Pydantic
Comprehensive field validation
Rich type conversion system
Clear error messages
Built-in SQLite Support
Ready to use with SQLite
Optimized for development and testing
Perfect for small to medium applications
No additional dependencies required
Rich Relationship Support
BelongsTo associations
HasOne relationships
HasMany connections
Easy relationship navigation
Advanced Features
Fluent query builder
Transaction management with savepoints
Event system for model lifecycle
Optimistic locking
Soft delete capability
UUID support
Connection pooling
Extensible Backend System
Built-in SQLite backend
Optional MySQL support
Optional PostgreSQL support
Easy custom backend creation
Installation
You can install RhoSocial ActiveRecord using pip:
# Core package with SQLite support
pip install rhosocial-activerecord
# Optional database backends
pip install rhosocial-activerecord[mysql] # MySQL support
pip install rhosocial-activerecord[pgsql] # PostgreSQL support
# All database backends
pip install rhosocial-activerecord[databases]
# Everything including optional features
pip install rhosocial-activerecord[all]
You can also install directly from GitHub:
pip install git+https://github.com/rhosocial/python-activerecord.git
Requirements
Python 3.10 or higher
Pydantic 2.10+
SQLite 3.35+ (for built-in backend)
Note: SQLite version must be 3.35 or higher for full functionality. You can check your SQLite version with:
import sqlite3
print(sqlite3.sqlite_version)
Quick Start
Here's a simple example to get you started:
from rhosocial.activerecord import ActiveRecord
from rhosocial.activerecord.backend.impl.sqlite.backend import SQLiteBackend
from rhosocial.activerecord.backend.typing import ConnectionConfig
from datetime import datetime
# Define your model
class User(ActiveRecord):
__table_name__ = 'users'
id: int
username: str
email: str
created_at: datetime
# Configure the database
User.configure(
ConnectionConfig(database='app.db'),
backend_class=SQLiteBackend
)
# Create a new user
user = User(
username='john_doe',
email='[email protected]',
created_at=datetime.now()
)
user.save()
# Query users
active_users = User.query()\
.where('status = ?', ('active',))\
.order_by('created_at DESC')\
.all()
Support Development
rhosocial ActiveRecord is an open source project that depends on your support. If you find it useful, please consider:
Visit our Sponsorship Page to learn more about supporting the project.
Community
GitHub Issues - Bug reports and feature requests
GitHub Discussions - General discussion and questions
Documentation - Official documentation
Last updated