# ODBMS - Object Document/Relational Mapping System
A flexible and modern Python ORM supporting multiple databases (MongoDB, PostgreSQL, MySQL) with both synchronous and asynchronous operations.
## Features
- Support for multiple databases:
- SQLite (using sqlite3)
- MongoDB (using Motor)
- PostgreSQL (using aiopg)
- MySQL (using aiomysql)
- Both synchronous and asynchronous operations
- Connection pooling for better performance
- Type-safe field definitions
- Pydantic integration for validation
- Automatic table/collection creation
- Relationship handling
- Computed fields
- Flexible query interface
## Installation
```bash
pip install -r requirements.txt
```
## Quick Start
```python
from odbms import Model, StringField, IntegerField, EmailField
from odbms.dbms import DBMS
# Initialize database connection
DBMS.initialize(
dbms='postgresql', # or 'mongodb', 'mysql'
host='localhost',
port=5432,
database='mydb',
username='user',
password='pass'
)
# Define your model
class User(Model):
name: str = StringField()
email: str = EmailField()
age: int = IntegerField(min_value=0)
# Create a new user
user = User(name='John Doe', email='john@example.com', age=30)
await user.save_async() # or user.save() for sync operation
# Find users
users = await User.find_async({'age': {'$gte': 25}}) # or User.find() for sync
```
## Field Types
- `StringField`: For text data
- `IntegerField`: For integer values
- `FloatField`: For floating-point numbers
- `BooleanField`: For true/false values
- `DateTimeField`: For timestamps
- `EmailField`: For email addresses with validation
- `IDField`: For primary keys/IDs
- `ComputedField`: For dynamically computed values
- `ListField`: For arrays/lists
- `DictField`: For nested documents/objects
## Database Operations
### Synchronous Operations
```python
# Create
user = User(name='John', email='john@example.com')
user.save()
# Read
user = User.find_one({'email': 'john@example.com'})
users = User.find({'age': {'$gte': 25}})
all_users = User.all()
# Update
User.update({'age': {'$lt': 18}}, {'is_minor': True})
# Delete
User.remove({'status': 'inactive'})
# Aggregation
total_age = User.sum('age', {'country': 'US'})
```
### Asynchronous Operations
```python
# Create
user = User(name='Jane', email='jane@example.com')
await user.save_async()
# Read
user = await User.find_one_async({'email': 'jane@example.com'})
users = await User.find_async({'age': {'$gte': 25}})
all_users = await User.all_async()
# Update
await User.update_async({'age': {'$lt': 18}}, {'is_minor': True})
# Delete
await User.remove_async({'status': 'inactive'})
# Aggregation
total_age = await User.sum_async('age', {'country': 'US'})
```
## Relationships
```python
class Post(Model):
title: str = StringField()
content: str = StringField()
author_id: str = IDField()
class User(Model):
name: str = StringField()
posts: List[Post] = ListField(model=Post)
# Create related records
user = User(name='John')
await user.save_async()
post = Post(title='Hello', content='World', author_id=user.id)
await post.save_async()
# Access relationships
user_posts = await user.posts # Automatically fetches related posts
```
## Testing
Run the test suite:
```bash
pytest tests/
```
The test suite includes comprehensive tests for:
- All database operations (CRUD)
- Both sync and async operations
- Field validations
- Relationships
- Computed fields
- Aggregations
## Requirements
- Python 3.7+
- pydantic >= 2.0.0
- motor >= 3.3.0 (for MongoDB)
- aiopg >= 1.4.0 (for PostgreSQL)
- aiomysql >= 0.2.0 (for MySQL)
- inflect >= 5.0.0
- python-dotenv >= 0.19.0
## Contributing
1. Fork the repository
2. Create a feature branch
3. Commit your changes
4. Push to the branch
5. Create a Pull Request
## License
MIT License
Raw data
{
"_id": null,
"home_page": null,
"name": "odbms",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "python3 runit developer serverless architecture docker sqlite mysql mongodb",
"author": "Amos Amissah",
"author_email": "theonlyamos@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/31/70/da1dd84e1bbf6b5d9e8cb75cff71b646c2036a1c4faa89e5d29e9b6b9ce5/odbms-0.4.4.tar.gz",
"platform": null,
"description": "# ODBMS - Object Document/Relational Mapping System\n\nA flexible and modern Python ORM supporting multiple databases (MongoDB, PostgreSQL, MySQL) with both synchronous and asynchronous operations.\n\n## Features\n\n- Support for multiple databases:\n - SQLite (using sqlite3)\n - MongoDB (using Motor)\n - PostgreSQL (using aiopg)\n - MySQL (using aiomysql)\n- Both synchronous and asynchronous operations\n- Connection pooling for better performance\n- Type-safe field definitions\n- Pydantic integration for validation\n- Automatic table/collection creation\n- Relationship handling\n- Computed fields\n- Flexible query interface\n\n## Installation\n\n```bash\npip install -r requirements.txt\n```\n\n## Quick Start\n\n```python\nfrom odbms import Model, StringField, IntegerField, EmailField\nfrom odbms.dbms import DBMS\n\n# Initialize database connection\nDBMS.initialize(\n dbms='postgresql', # or 'mongodb', 'mysql'\n host='localhost',\n port=5432,\n database='mydb',\n username='user',\n password='pass'\n)\n\n# Define your model\nclass User(Model):\n name: str = StringField()\n email: str = EmailField()\n age: int = IntegerField(min_value=0)\n\n# Create a new user\nuser = User(name='John Doe', email='john@example.com', age=30)\nawait user.save_async() # or user.save() for sync operation\n\n# Find users\nusers = await User.find_async({'age': {'$gte': 25}}) # or User.find() for sync\n```\n\n## Field Types\n\n- `StringField`: For text data\n- `IntegerField`: For integer values\n- `FloatField`: For floating-point numbers\n- `BooleanField`: For true/false values\n- `DateTimeField`: For timestamps\n- `EmailField`: For email addresses with validation\n- `IDField`: For primary keys/IDs\n- `ComputedField`: For dynamically computed values\n- `ListField`: For arrays/lists\n- `DictField`: For nested documents/objects\n\n## Database Operations\n\n### Synchronous Operations\n\n```python\n# Create\nuser = User(name='John', email='john@example.com')\nuser.save()\n\n# Read\nuser = User.find_one({'email': 'john@example.com'})\nusers = User.find({'age': {'$gte': 25}})\nall_users = User.all()\n\n# Update\nUser.update({'age': {'$lt': 18}}, {'is_minor': True})\n\n# Delete\nUser.remove({'status': 'inactive'})\n\n# Aggregation\ntotal_age = User.sum('age', {'country': 'US'})\n```\n\n### Asynchronous Operations\n\n```python\n# Create\nuser = User(name='Jane', email='jane@example.com')\nawait user.save_async()\n\n# Read\nuser = await User.find_one_async({'email': 'jane@example.com'})\nusers = await User.find_async({'age': {'$gte': 25}})\nall_users = await User.all_async()\n\n# Update\nawait User.update_async({'age': {'$lt': 18}}, {'is_minor': True})\n\n# Delete\nawait User.remove_async({'status': 'inactive'})\n\n# Aggregation\ntotal_age = await User.sum_async('age', {'country': 'US'})\n```\n\n## Relationships\n\n```python\nclass Post(Model):\n title: str = StringField()\n content: str = StringField()\n author_id: str = IDField()\n\nclass User(Model):\n name: str = StringField()\n posts: List[Post] = ListField(model=Post)\n\n# Create related records\nuser = User(name='John')\nawait user.save_async()\n\npost = Post(title='Hello', content='World', author_id=user.id)\nawait post.save_async()\n\n# Access relationships\nuser_posts = await user.posts # Automatically fetches related posts\n```\n\n## Testing\n\nRun the test suite:\n\n```bash\npytest tests/\n```\n\nThe test suite includes comprehensive tests for:\n\n- All database operations (CRUD)\n- Both sync and async operations\n- Field validations\n- Relationships\n- Computed fields\n- Aggregations\n\n## Requirements\n\n- Python 3.7+\n- pydantic >= 2.0.0\n- motor >= 3.3.0 (for MongoDB)\n- aiopg >= 1.4.0 (for PostgreSQL)\n- aiomysql >= 0.2.0 (for MySQL)\n- inflect >= 5.0.0\n- python-dotenv >= 0.19.0\n\n## Contributing\n\n1. Fork the repository\n2. Create a feature branch\n3. Commit your changes\n4. Push to the branch\n5. Create a Pull Request\n\n## License\n\nMIT License\n",
"bugtrack_url": null,
"license": null,
"summary": "Database client for Mysql, MongoDB and Sqlite",
"version": "0.4.4",
"project_urls": {
"Source": "https://github.com/theonlyamos/odbms/",
"Tracker": "https://github.com/theonlyamos/odbms/issues"
},
"split_keywords": [
"python3",
"runit",
"developer",
"serverless",
"architecture",
"docker",
"sqlite",
"mysql",
"mongodb"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "23fee4fb97210cdc3658f68ca96e180f10a3b019e3cddd59d451072288db7935",
"md5": "59001a643f19aae8a371f8d608dc9971",
"sha256": "efdce262bc654ff6907991aeaf054e76a548236bdbe40edc41da7ae81e09bb5e"
},
"downloads": -1,
"filename": "odbms-0.4.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "59001a643f19aae8a371f8d608dc9971",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 40280,
"upload_time": "2024-12-30T13:05:37",
"upload_time_iso_8601": "2024-12-30T13:05:37.706038Z",
"url": "https://files.pythonhosted.org/packages/23/fe/e4fb97210cdc3658f68ca96e180f10a3b019e3cddd59d451072288db7935/odbms-0.4.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3170da1dd84e1bbf6b5d9e8cb75cff71b646c2036a1c4faa89e5d29e9b6b9ce5",
"md5": "6c439097fc126653eb67461dac02a44e",
"sha256": "84e6265d630ea79b9e53a8d6f06b56ed5f0e6f4f779395bf7791b6283c39a6f9"
},
"downloads": -1,
"filename": "odbms-0.4.4.tar.gz",
"has_sig": false,
"md5_digest": "6c439097fc126653eb67461dac02a44e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 43183,
"upload_time": "2024-12-30T13:05:40",
"upload_time_iso_8601": "2024-12-30T13:05:40.261812Z",
"url": "https://files.pythonhosted.org/packages/31/70/da1dd84e1bbf6b5d9e8cb75cff71b646c2036a1c4faa89e5d29e9b6b9ce5/odbms-0.4.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-30 13:05:40",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "theonlyamos",
"github_project": "odbms",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "pydantic",
"specs": [
[
">=",
"2.0.0"
]
]
},
{
"name": "inflect",
"specs": [
[
">=",
"5.0.0"
]
]
},
{
"name": "python-dotenv",
"specs": [
[
">=",
"0.19.0"
]
]
},
{
"name": "motor",
"specs": [
[
">=",
"3.3.0"
]
]
},
{
"name": "aiopg",
"specs": [
[
">=",
"1.4.0"
]
]
},
{
"name": "aiomysql",
"specs": [
[
">=",
"0.2.0"
]
]
}
],
"lcname": "odbms"
}