# EasyModel
A simplified SQLModel-based ORM for async database operations in Python. EasyModel provides a clean and intuitive interface for common database operations while leveraging the power of SQLModel and SQLAlchemy.
## Features
- Easy-to-use async database operations
- Built on top of SQLModel and SQLAlchemy
- PostgreSQL support with asyncpg
- Common CRUD operations out of the box
- Session management with context managers
- Type hints for better IDE support
- Automatic `updated_at` field updates
## Installation
```bash
pip install async-easy-model
```
## Quick Start
```python
from easy_model import EasyModel, init_db
from sqlmodel import Field
from typing import Optional
from datetime import datetime
# Define your model
class User(EasyModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
username: str = Field(unique=True)
email: str
created_at: datetime = Field(default_factory=datetime.utcnow)
updated_at: datetime = Field(default=None) # Will be automatically updated
# Initialize your database (creates all tables)
async def setup():
await init_db()
# Use it in your async code
async def main():
# Create a new user
user = await User.insert({
"username": "john_doe",
"email": "john@example.com"
})
# Get user by id
user = await User.get_by_id(1)
# Get user by attribute
user = await User.get_by_attribute(username="john_doe")
# Update user - updated_at will be automatically set
updated_user = await User.update(1, {
"email": "new_email@example.com"
})
print(f"Last update: {updated_user.updated_at}")
# Delete user
success = await User.delete(1)
```
## Configuration
Set your database connection details using environment variables:
```bash
POSTGRES_USER=your_user
POSTGRES_PASSWORD=your_password
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_DB=your_database
```
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
## License
This project is licensed under the MIT License - see the LICENSE file for details.
Raw data
{
"_id": null,
"home_page": "https://github.com/puntorigen/easy-model",
"name": "async-easy-model",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "orm, sqlmodel, database, async, postgresql",
"author": "Pablo Schaffner",
"author_email": "pablo@puntorigen.com",
"download_url": "https://files.pythonhosted.org/packages/97/8b/32eeaaba7645c89aa40732032965919a7295aac9e57fecb2e841191f28b2/async_easy_model-0.0.1.tar.gz",
"platform": null,
"description": "# EasyModel\n\nA simplified SQLModel-based ORM for async database operations in Python. EasyModel provides a clean and intuitive interface for common database operations while leveraging the power of SQLModel and SQLAlchemy.\n\n## Features\n\n- Easy-to-use async database operations\n- Built on top of SQLModel and SQLAlchemy\n- PostgreSQL support with asyncpg\n- Common CRUD operations out of the box\n- Session management with context managers\n- Type hints for better IDE support\n- Automatic `updated_at` field updates\n\n## Installation\n\n```bash\npip install async-easy-model\n```\n\n## Quick Start\n\n```python\nfrom easy_model import EasyModel, init_db\nfrom sqlmodel import Field\nfrom typing import Optional\nfrom datetime import datetime\n\n# Define your model\nclass User(EasyModel, table=True):\n id: Optional[int] = Field(default=None, primary_key=True)\n username: str = Field(unique=True)\n email: str\n created_at: datetime = Field(default_factory=datetime.utcnow)\n updated_at: datetime = Field(default=None) # Will be automatically updated\n\n# Initialize your database (creates all tables)\nasync def setup():\n await init_db()\n\n# Use it in your async code\nasync def main():\n # Create a new user\n user = await User.insert({\n \"username\": \"john_doe\",\n \"email\": \"john@example.com\"\n })\n\n # Get user by id\n user = await User.get_by_id(1)\n\n # Get user by attribute\n user = await User.get_by_attribute(username=\"john_doe\")\n\n # Update user - updated_at will be automatically set\n updated_user = await User.update(1, {\n \"email\": \"new_email@example.com\"\n })\n print(f\"Last update: {updated_user.updated_at}\")\n\n # Delete user\n success = await User.delete(1)\n```\n\n## Configuration\n\nSet your database connection details using environment variables:\n\n```bash\nPOSTGRES_USER=your_user\nPOSTGRES_PASSWORD=your_password\nPOSTGRES_HOST=localhost\nPOSTGRES_PORT=5432\nPOSTGRES_DB=your_database\n```\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nThis project is licensed under the MIT License - see the LICENSE file for details.\n",
"bugtrack_url": null,
"license": null,
"summary": "A simplified SQLModel-based ORM for async database operations",
"version": "0.0.1",
"project_urls": {
"Homepage": "https://github.com/puntorigen/easy-model"
},
"split_keywords": [
"orm",
" sqlmodel",
" database",
" async",
" postgresql"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "2bfd246edddcd5a7a6c3eed5150b8b520bc2ec4309b0c559bc894a5d783a37a2",
"md5": "5b625ec87645a052520be5c69d99062c",
"sha256": "0a79d1d90e47f6583fc584a033bc2ff0612412ecb2beae68fd81b51af18b0092"
},
"downloads": -1,
"filename": "async_easy_model-0.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "5b625ec87645a052520be5c69d99062c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 5468,
"upload_time": "2025-02-20T03:57:12",
"upload_time_iso_8601": "2025-02-20T03:57:12.520480Z",
"url": "https://files.pythonhosted.org/packages/2b/fd/246edddcd5a7a6c3eed5150b8b520bc2ec4309b0c559bc894a5d783a37a2/async_easy_model-0.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "978b32eeaaba7645c89aa40732032965919a7295aac9e57fecb2e841191f28b2",
"md5": "1110e31c9a77d730652c0d5d97297dab",
"sha256": "eba654dda25511c0fc061d4c3ace59c8c6ae860fd2c0948626e5bdeb7ee5ee67"
},
"downloads": -1,
"filename": "async_easy_model-0.0.1.tar.gz",
"has_sig": false,
"md5_digest": "1110e31c9a77d730652c0d5d97297dab",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 5537,
"upload_time": "2025-02-20T03:57:14",
"upload_time_iso_8601": "2025-02-20T03:57:14.583737Z",
"url": "https://files.pythonhosted.org/packages/97/8b/32eeaaba7645c89aa40732032965919a7295aac9e57fecb2e841191f28b2/async_easy_model-0.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-20 03:57:14",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "puntorigen",
"github_project": "easy-model",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "async-easy-model"
}