# FastRecord
A Rails-like ORM for FastAPI using SQLModel, bringing Active Record pattern to Python.
## Version Compatibility
| FastRecord | Python | FastAPI | SQLModel | Redis |
|------------|--------|----------|----------|--------|
| 0.1.x | ≥3.9 | ≥0.115.5 | ≥0.0.22 | ≥5.2.0 |
### Requirements
- **Python**: 3.9 or higher required for modern typing features and performance improvements
- **FastAPI**: 0.115.5 or higher for middleware and dependency injection features
- **SQLModel**: 0.0.22 or higher for ORM functionality
- **Redis**: 5.2.0 or higher (with hiredis) for caching support
- **Pydantic Settings**: 2.6.1 or higher for configuration management
- **Inflect**: 7.4.0 or higher for naming conventions
[Previous README content remains the same...]
## Features
- Active Record pattern implementation
- Chainable query interface
- Built-in caching with Redis/memory support
- Callbacks (before/after save, create, update, destroy)
- Validations
- Relationship management (has_many, belongs_to, has_one)
- Soft deletes
- Pagination
- Eager loading
## Installation
```bash
pip install fastrecord
```
## Quick Start
```python
from fastrecord import FastRecord, Field
from typing import Optional, List
from datetime import datetime
class User(FastRecord):
name: str = Field(...)
email: str = Field(...)
posts: List["Post"] = []
class Post(FastRecord):
title: str = Field(...)
content: str = Field(...)
author_id: Optional[int] = Field(default=None, foreign_key="user.id")
author: Optional[User] = None
# Create
user = User.create(name="John", email="john@example.com")
# Query
user = User.where(name="John").first()
posts = Post.where(author_id=user.id).order("created_at").limit(5).all()
# Update
user.update(name="John Doe")
# Delete
user.delete() # Soft delete
user.destroy() # Hard delete
```
## Configuration
```python
from fastrecord import configure
configure(
DATABASE_URL="postgresql://user:pass@localhost/dbname",
CACHE_ENABLED=True,
CACHE_TYPE="redis",
CACHE_REDIS_URL="redis://localhost:6379/0"
)
```
## FastAPI Integration
```python
from fastapi import FastAPI
from fastrecord import DatabaseMiddleware
app = FastAPI()
app.add_middleware(DatabaseMiddleware)
```
## Validations
```python
from fastrecord.validation import PresenceValidator, FormatValidator
class User(FastRecord):
name: str = Field(...)
email: str = Field(...)
@validates("name", PresenceValidator)
def validate_name(self):
pass
@validates("email", FormatValidator, with_=r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$')
def validate_email(self):
pass
```
## Relationships
```python
class User(FastRecord):
posts = has_many("Post")
profile = has_one("Profile")
class Post(FastRecord):
author = belongs_to("User")
```
## Caching
```python
class User(FastRecord):
@cached(ttl=3600)
def expensive_calculation(self):
# Complex computation
pass
# Query caching
users = User.where(active=True).cache(ttl=300).all()
```
## License
MIT License. See [LICENSE](./LICENSE.md) file for details.
## Contributing
1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request
## Author
Tushar Mangukiya <tushar.m@innovalabs.tech>
# FastRecord Examples
- [Example.md](./Example.md)
- [Cache Example.md](./Cache%20Example.md)
- [Advanced Usage Examples.md](./Advanced%20Usage%20Examples.md)
Raw data
{
"_id": null,
"home_page": "https://github.com/innovalabs-tech/fastrecord#readme",
"name": "fastrecord",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": "fastapi, orm, database, sqlmodel, rails",
"author": "Tushar Mangukiya",
"author_email": "tushar.m@innovalabs.tech",
"download_url": "https://files.pythonhosted.org/packages/62/07/5d2cf4fa3defefe9c7ee5f07bcb0645512fbe6789f2049f0cc83a364c816/fastrecord-0.1.1.tar.gz",
"platform": null,
"description": "# FastRecord\n\nA Rails-like ORM for FastAPI using SQLModel, bringing Active Record pattern to Python.\n\n## Version Compatibility\n\n| FastRecord | Python | FastAPI | SQLModel | Redis |\n|------------|--------|----------|----------|--------|\n| 0.1.x | \u22653.9 | \u22650.115.5 | \u22650.0.22 | \u22655.2.0 |\n\n### Requirements\n\n- **Python**: 3.9 or higher required for modern typing features and performance improvements\n- **FastAPI**: 0.115.5 or higher for middleware and dependency injection features\n- **SQLModel**: 0.0.22 or higher for ORM functionality\n- **Redis**: 5.2.0 or higher (with hiredis) for caching support\n- **Pydantic Settings**: 2.6.1 or higher for configuration management\n- **Inflect**: 7.4.0 or higher for naming conventions\n\n[Previous README content remains the same...]\n\n## Features\n\n- Active Record pattern implementation\n- Chainable query interface\n- Built-in caching with Redis/memory support\n- Callbacks (before/after save, create, update, destroy)\n- Validations\n- Relationship management (has_many, belongs_to, has_one)\n- Soft deletes\n- Pagination\n- Eager loading\n\n## Installation\n\n```bash\npip install fastrecord\n```\n\n## Quick Start\n\n```python\nfrom fastrecord import FastRecord, Field\nfrom typing import Optional, List\nfrom datetime import datetime\n\n\nclass User(FastRecord):\n name: str = Field(...)\n email: str = Field(...)\n posts: List[\"Post\"] = []\n\n\nclass Post(FastRecord):\n title: str = Field(...)\n content: str = Field(...)\n author_id: Optional[int] = Field(default=None, foreign_key=\"user.id\")\n author: Optional[User] = None\n\n\n# Create\nuser = User.create(name=\"John\", email=\"john@example.com\")\n\n# Query\nuser = User.where(name=\"John\").first()\nposts = Post.where(author_id=user.id).order(\"created_at\").limit(5).all()\n\n# Update\nuser.update(name=\"John Doe\")\n\n# Delete\nuser.delete() # Soft delete\nuser.destroy() # Hard delete\n```\n\n## Configuration\n\n```python\nfrom fastrecord import configure\n\nconfigure(\n DATABASE_URL=\"postgresql://user:pass@localhost/dbname\",\n CACHE_ENABLED=True,\n CACHE_TYPE=\"redis\",\n CACHE_REDIS_URL=\"redis://localhost:6379/0\"\n)\n```\n\n## FastAPI Integration\n\n```python\nfrom fastapi import FastAPI\nfrom fastrecord import DatabaseMiddleware\n\napp = FastAPI()\napp.add_middleware(DatabaseMiddleware)\n```\n\n## Validations\n\n```python\nfrom fastrecord.validation import PresenceValidator, FormatValidator\n\n\nclass User(FastRecord):\n name: str = Field(...)\n email: str = Field(...)\n\n @validates(\"name\", PresenceValidator)\n def validate_name(self):\n pass\n\n @validates(\"email\", FormatValidator, with_=r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$')\n def validate_email(self):\n pass\n```\n\n## Relationships\n\n```python\nclass User(FastRecord):\n posts = has_many(\"Post\")\n profile = has_one(\"Profile\")\n\n\nclass Post(FastRecord):\n author = belongs_to(\"User\")\n```\n\n## Caching\n\n```python\nclass User(FastRecord):\n @cached(ttl=3600)\n def expensive_calculation(self):\n # Complex computation\n pass\n\n\n# Query caching\nusers = User.where(active=True).cache(ttl=300).all()\n```\n\n## License\n\nMIT License. See [LICENSE](./LICENSE.md) file for details.\n\n## Contributing\n\n1. Fork the repository\n2. Create your feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit your changes (`git commit -m 'Add amazing feature'`)\n4. Push to the branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n\n## Author\n\nTushar Mangukiya <tushar.m@innovalabs.tech>\n\n# FastRecord Examples\n\n- [Example.md](./Example.md)\n- [Cache Example.md](./Cache%20Example.md)\n- [Advanced Usage Examples.md](./Advanced%20Usage%20Examples.md)",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Rails-like ORM for FastAPI using SQLModel",
"version": "0.1.1",
"project_urls": {
"Homepage": "https://github.com/innovalabs-tech/fastrecord#readme",
"Repository": "https://github.com/innovalabs-tech/fastrecord"
},
"split_keywords": [
"fastapi",
" orm",
" database",
" sqlmodel",
" rails"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a41710d50396b96405129bdeb5147a5576b4178c0f0ad198aeb4c1e163a4cbf1",
"md5": "09835ac4411e0a2f1b05b3551ac0c39a",
"sha256": "7d4dbfad8268db6ec64825d177fcfc702cbb84b02cbfd1d6ac0c12bb98a5ecf5"
},
"downloads": -1,
"filename": "fastrecord-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "09835ac4411e0a2f1b05b3551ac0c39a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 29857,
"upload_time": "2024-12-02T08:27:23",
"upload_time_iso_8601": "2024-12-02T08:27:23.638027Z",
"url": "https://files.pythonhosted.org/packages/a4/17/10d50396b96405129bdeb5147a5576b4178c0f0ad198aeb4c1e163a4cbf1/fastrecord-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "62075d2cf4fa3defefe9c7ee5f07bcb0645512fbe6789f2049f0cc83a364c816",
"md5": "5affbeb2c0f1cbf62b1c2f8d55bd221a",
"sha256": "152e50204eaa86cfe2af6f6697a9efa6aa4ea45b8b4dc3f151cd0ed5ec38b6f7"
},
"downloads": -1,
"filename": "fastrecord-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "5affbeb2c0f1cbf62b1c2f8d55bd221a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 20588,
"upload_time": "2024-12-02T08:27:25",
"upload_time_iso_8601": "2024-12-02T08:27:25.368446Z",
"url": "https://files.pythonhosted.org/packages/62/07/5d2cf4fa3defefe9c7ee5f07bcb0645512fbe6789f2049f0cc83a364c816/fastrecord-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-02 08:27:25",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "innovalabs-tech",
"github_project": "fastrecord#readme",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "fastrecord"
}