# 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
- Support for both PostgreSQL and SQLite databases
- 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 async_easy_model import EasyModel, init_db, db_config
from sqlmodel import Field
from typing import Optional
from datetime import datetime
# Configure your database (choose one)
# For SQLite:
db_config.configure_sqlite("database.db")
# For PostgreSQL:
db_config.configure_postgres(
user="your_user",
password="your_password",
host="localhost",
port="5432",
database="your_database"
)
# 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
**Note:** The `updated_at` field is optional since it is included by default in all EasyModel models. However, if you choose to override it, please ensure it always defines a default value as it is automatically updated. If specified, missing a default value will cause tests to fail.
# 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"
})
# 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
You can configure the database connection in two ways:
### 1. Using Environment Variables
For PostgreSQL:
```bash
POSTGRES_USER=your_user
POSTGRES_PASSWORD=your_password
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_DB=your_database
```
For SQLite:
```bash
SQLITE_FILE=database.db
```
### 2. Using Configuration Methods
For PostgreSQL:
```python
from async_easy_model import db_config
db_config.configure_postgres(
user="your_user",
password="your_password",
host="localhost",
port="5432",
database="your_database"
)
```
For SQLite:
```python
from async_easy_model import db_config
db_config.configure_sqlite("database.db")
```
## 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/async-easy-model",
"name": "async-easy-model",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "orm, sqlmodel, database, async, postgresql, sqlite",
"author": "Pablo Schaffner",
"author_email": "pablo@puntorigen.com",
"download_url": "https://files.pythonhosted.org/packages/63/86/7ef39d16f41cc5ed42f6e6d113061e16bf7c583f92ee7694eac6c471fb73/async_easy_model-0.0.2.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- Support for both PostgreSQL and SQLite databases\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 async_easy_model import EasyModel, init_db, db_config\nfrom sqlmodel import Field\nfrom typing import Optional\nfrom datetime import datetime\n\n# Configure your database (choose one)\n# For SQLite:\ndb_config.configure_sqlite(\"database.db\")\n# For PostgreSQL:\ndb_config.configure_postgres(\n user=\"your_user\",\n password=\"your_password\",\n host=\"localhost\",\n port=\"5432\",\n database=\"your_database\"\n)\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 **Note:** The `updated_at` field is optional since it is included by default in all EasyModel models. However, if you choose to override it, please ensure it always defines a default value as it is automatically updated. If specified, missing a default value will cause tests to fail.\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 # 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\nYou can configure the database connection in two ways:\n\n### 1. Using Environment Variables\n\nFor PostgreSQL:\n```bash\nPOSTGRES_USER=your_user\nPOSTGRES_PASSWORD=your_password\nPOSTGRES_HOST=localhost\nPOSTGRES_PORT=5432\nPOSTGRES_DB=your_database\n```\n\nFor SQLite:\n```bash\nSQLITE_FILE=database.db\n```\n\n### 2. Using Configuration Methods\n\nFor PostgreSQL:\n```python\nfrom async_easy_model import db_config\n\ndb_config.configure_postgres(\n user=\"your_user\",\n password=\"your_password\",\n host=\"localhost\",\n port=\"5432\",\n database=\"your_database\"\n)\n```\n\nFor SQLite:\n```python\nfrom async_easy_model import db_config\n\ndb_config.configure_sqlite(\"database.db\")\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.2",
"project_urls": {
"Homepage": "https://github.com/puntorigen/async-easy-model"
},
"split_keywords": [
"orm",
" sqlmodel",
" database",
" async",
" postgresql",
" sqlite"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "f9a25d1d20906d37a994965f73af444353d544af5b746558b7e42b14b0b5b98e",
"md5": "2acd113f9801d2587d97ea0459696687",
"sha256": "847fdcea8d46fc6885abbcb23e8429b075b8e8526b6c1866392d2218fc741ead"
},
"downloads": -1,
"filename": "async_easy_model-0.0.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2acd113f9801d2587d97ea0459696687",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 5878,
"upload_time": "2025-02-23T14:43:50",
"upload_time_iso_8601": "2025-02-23T14:43:50.701326Z",
"url": "https://files.pythonhosted.org/packages/f9/a2/5d1d20906d37a994965f73af444353d544af5b746558b7e42b14b0b5b98e/async_easy_model-0.0.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "63867ef39d16f41cc5ed42f6e6d113061e16bf7c583f92ee7694eac6c471fb73",
"md5": "bf223dbc5f7d631fc57bbd0866e848d7",
"sha256": "d2a2cc37e8a3b0e02249ff2f09539e9a5d8f97e48b24b82c997caa09b5fa501f"
},
"downloads": -1,
"filename": "async_easy_model-0.0.2.tar.gz",
"has_sig": false,
"md5_digest": "bf223dbc5f7d631fc57bbd0866e848d7",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 6744,
"upload_time": "2025-02-23T14:43:52",
"upload_time_iso_8601": "2025-02-23T14:43:52.424281Z",
"url": "https://files.pythonhosted.org/packages/63/86/7ef39d16f41cc5ed42f6e6d113061e16bf7c583f92ee7694eac6c471fb73/async_easy_model-0.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-23 14:43:52",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "puntorigen",
"github_project": "async-easy-model",
"github_not_found": true,
"lcname": "async-easy-model"
}