<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/SpaceShaman/ORMagic/raw/master/docs/assets/logo-light.png">
<img src="https://github.com/SpaceShaman/ORMagic/raw/master/docs/assets/logo-dark.png" alt="ORMagic">
</picture>
<!--intro-start-->
[![GitHub License](https://img.shields.io/github/license/SpaceShaman/ORMagic)](https://github.com/SpaceShaman/ORMagic?tab=MIT-1-ov-file)
[![Tests](https://img.shields.io/github/actions/workflow/status/SpaceShaman/ORMagic/release.yml?label=tests)](https://github.com/SpaceShaman/ORMagic/blob/master/.github/workflows/tests.yml)
[![Codecov](https://img.shields.io/codecov/c/github/SpaceShaman/ORMagic)](https://codecov.io/gh/SpaceShaman/ORMagic)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/ORMagic)](https://pypi.org/project/ORMagic)
[![PyPI - Version](https://img.shields.io/pypi/v/ORMagic)](https://pypi.org/project/ORMagic)
[![Code style: black](https://img.shields.io/badge/code%20style-black-black)](https://github.com/psf/black)
[![Linting: Ruff](https://img.shields.io/badge/linting-Ruff-black?logo=ruff&logoColor=black)](https://github.com/astral-sh/ruff)
[![Pydantic](https://img.shields.io/badge/technology-Pydantic-blue?logo=pydantic&logoColor=blue)](https://docs.pydantic.dev)
[![SQLite](https://img.shields.io/badge/technology-SQLite-blue?logo=sqlite&logoColor=blue)](https://www.sqlite.org)
[![PostgreSQL](https://img.shields.io/badge/technology-PostgreSQL-blue?logo=postgresql&logoColor=blue)](https://www.postgresql.org)
[![Pytest](https://img.shields.io/badge/testing-Pytest-red?logo=pytest&logoColor=red)](https://docs.pytest.org/)
[![Material for MkDocs](https://img.shields.io/badge/docs-Material%20for%20MkDocs-yellow?logo=MaterialForMkDocs&logoColor=yellow)](https://spaceshaman.github.io/ORMagic/)
The main goal of ORMagic is to provide a simple and easy-to-use ORM for [Python](https://www.python.org/), that is easy to understand and use, while still providing the necessary features to interact with a database.
Is based on the [Pydantic](https://docs.pydantic.dev) model and extends it with the ability to interact with [SQLite](https://www.sqlite.org) and [PostgreSQL](https://www.postgresql.org) databases.
## Simple example
```python
from ormagic import DBModel
class User(DBModel):
name: str
age: int
User.create_table()
User(name="John", age=30).save()
User.get(name="John")
>>> User(id=1, name='John', age=30)
```
<!--intro-end-->
You can find more examples and detailed documentation at [spaceshaman.github.io/ORMagic/](https://spaceshaman.github.io/ORMagic/)
## Installation
<!--installation-start-->
You can install ORMagic using pip:
```bash
pip install ORMagic
```
By default, ORMagic uses [SQLite](https://www.sqlite.org) as a database, so you don't need to install any additional dependencies.
But if you want to use another database, you need to install the appropriate database driver, for example,
for [PostgreSQL](https://www.postgresql.org) you need to install [psycopg2](https://github.com/psycopg/psycopg2), you can do it with the following command:
```bash
pip install ORMagic[postgres]
```
Additionally, to use a database other than [SQLite](https://www.sqlite.org), you need to set the `ORMAGIC_DATABASE_URL` environment,
more information about that you can find in the [documentation](https://spaceshaman.github.io/ORMagic/settings/).
<!--installation-end-->
## Documentation
The full documentation is available at [spaceshaman.github.io/ORMagic/](https://spaceshaman.github.io/ORMagic/)
## Features and Roadmap
<!--roadmap-start-->
- [x] Define table schema using Pydantic models
- [x] Basic CRUD operations
- [x] Save data to the database
- [x] Read data from the database
- [x] Update data in the database
- [x] Delete data from the database
- [x] Relationships between tables
- [x] One-to-many
- [x] Create a tables with a foreign key
- [x] Save data with a foreign key
- [x] Read data with a foreign key
- [x] Update data with a foreign key
- [x] Delete data with a foreign key
- [X] Cascade
- [x] Set null
- [x] Restrict
- [x] Set default
- [x] No action
- [x] One-to-one
- [x] Many-to-many
- [x] Unique constraints
- [x] Remove table
- [x] Read all data from the database
- [x] Filter data and retrieve multiple records
- [x] Equal
- [x] Not equal
- [x] Greater than
- [x] Greater than or equal
- [x] Less than
- [x] Less than or equal
- [x] Like (Pattern matching with % and _)
- [x] Not like (Pattern matching with % and _)
- [x] In (List of values)
- [x] Not in (List of values)
- [x] Between (Two values)
- [x] Not between (Two values)
- [x] Q objects to combine filters (AND, OR, NOT)
- [x] Protect against SQL injection
- [x] Order by
- [x] Limit and offset
- [x] Update table schema
- [x] Add new column
- [x] Rename column
- [x] Drop column
- [x] Custom primary key
- [x] Transactions
- [x] Integration with databases
- [x] SQLite
- [x] PostgreSQL
- [ ] MySQL
- [ ] Functions
- [ ] Aggregate functions
- [ ] String functions
- [ ] Date and time functions
- [ ] Mathematical functions
- [ ] Control flow functions
- [ ] Migrations
<!--roadmap-end-->
## Changelog
<!--changelog-start-->
Changes for each release are thoroughly documented in [release notes](https://github.com/SpaceShaman/ORMagic/releases)
<!--changelog-end-->
## Contributing
<!--contributing-start-->
Contributions are welcome! Feel free to open an issue or submit a pull request.
I would like to keep the library to be safe as possible, so i would appreciate if you cover any new feature with tests to maintain 100% coverage.
### Install in a development environment
1. First, clone the repository:
```bash
git clone git@github.com:SpaceShaman/ORMagic.git
```
2. Install poetry if you don't have, here you can find the [instructions](https://python-poetry.org/docs/#installing-with-the-official-installer)
3. Create a virtual environment and install the dependencies:
```bash
cd ORMagic
poetry install --no-root
```
4. Activate the virtual environment:
```bash
poetry shell
```
### Run tests
If you in the virtual environment, you can run the tests with the following command:
```bash
pytest
```
You can also run the tests with coverage:
```bash
pytest --cov=ormagic
```
<!--contributing-end-->
## License
This project is licensed under the terms of the [MIT license](https://github.com/SpaceShaman/ORMagic?tab=MIT-1-ov-file)
Raw data
{
"_id": null,
"home_page": "https://spaceshaman.github.io/ORMagic/",
"name": "ORMagic",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.11",
"maintainer_email": null,
"keywords": "sql, orm, database, sqlite, db, sqlite3, pydantic, fastapi, postgresql, psycopg2, postgres",
"author": "SpaceShaman",
"author_email": "spaceshaman@tuta.io",
"download_url": "https://files.pythonhosted.org/packages/56/5e/809aa965f1e1e3871c6f9a3aedfbbd84fce916d90e17731668ad747d40cf/ormagic-0.16.1.tar.gz",
"platform": null,
"description": "<picture>\n <source media=\"(prefers-color-scheme: dark)\" srcset=\"https://github.com/SpaceShaman/ORMagic/raw/master/docs/assets/logo-light.png\">\n <img src=\"https://github.com/SpaceShaman/ORMagic/raw/master/docs/assets/logo-dark.png\" alt=\"ORMagic\">\n</picture>\n\n<!--intro-start-->\n[![GitHub License](https://img.shields.io/github/license/SpaceShaman/ORMagic)](https://github.com/SpaceShaman/ORMagic?tab=MIT-1-ov-file)\n[![Tests](https://img.shields.io/github/actions/workflow/status/SpaceShaman/ORMagic/release.yml?label=tests)](https://github.com/SpaceShaman/ORMagic/blob/master/.github/workflows/tests.yml)\n[![Codecov](https://img.shields.io/codecov/c/github/SpaceShaman/ORMagic)](https://codecov.io/gh/SpaceShaman/ORMagic)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/ORMagic)](https://pypi.org/project/ORMagic)\n[![PyPI - Version](https://img.shields.io/pypi/v/ORMagic)](https://pypi.org/project/ORMagic)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-black)](https://github.com/psf/black)\n[![Linting: Ruff](https://img.shields.io/badge/linting-Ruff-black?logo=ruff&logoColor=black)](https://github.com/astral-sh/ruff)\n[![Pydantic](https://img.shields.io/badge/technology-Pydantic-blue?logo=pydantic&logoColor=blue)](https://docs.pydantic.dev)\n[![SQLite](https://img.shields.io/badge/technology-SQLite-blue?logo=sqlite&logoColor=blue)](https://www.sqlite.org)\n[![PostgreSQL](https://img.shields.io/badge/technology-PostgreSQL-blue?logo=postgresql&logoColor=blue)](https://www.postgresql.org)\n[![Pytest](https://img.shields.io/badge/testing-Pytest-red?logo=pytest&logoColor=red)](https://docs.pytest.org/)\n[![Material for MkDocs](https://img.shields.io/badge/docs-Material%20for%20MkDocs-yellow?logo=MaterialForMkDocs&logoColor=yellow)](https://spaceshaman.github.io/ORMagic/)\n\nThe main goal of ORMagic is to provide a simple and easy-to-use ORM for [Python](https://www.python.org/), that is easy to understand and use, while still providing the necessary features to interact with a database.\nIs based on the [Pydantic](https://docs.pydantic.dev) model and extends it with the ability to interact with [SQLite](https://www.sqlite.org) and [PostgreSQL](https://www.postgresql.org) databases.\n\n## Simple example\n\n```python\nfrom ormagic import DBModel\n\nclass User(DBModel):\n name: str\n age: int\n\nUser.create_table()\n\nUser(name=\"John\", age=30).save()\n\nUser.get(name=\"John\")\n>>> User(id=1, name='John', age=30)\n```\n<!--intro-end-->\n\nYou can find more examples and detailed documentation at [spaceshaman.github.io/ORMagic/](https://spaceshaman.github.io/ORMagic/)\n\n## Installation\n\n<!--installation-start-->\nYou can install ORMagic using pip:\n\n```bash\npip install ORMagic\n```\n\nBy default, ORMagic uses [SQLite](https://www.sqlite.org) as a database, so you don't need to install any additional dependencies.\nBut if you want to use another database, you need to install the appropriate database driver, for example,\nfor [PostgreSQL](https://www.postgresql.org) you need to install [psycopg2](https://github.com/psycopg/psycopg2), you can do it with the following command:\n\n```bash\npip install ORMagic[postgres]\n```\n\nAdditionally, to use a database other than [SQLite](https://www.sqlite.org), you need to set the `ORMAGIC_DATABASE_URL` environment,\nmore information about that you can find in the [documentation](https://spaceshaman.github.io/ORMagic/settings/).\n<!--installation-end-->\n\n## Documentation\n\nThe full documentation is available at [spaceshaman.github.io/ORMagic/](https://spaceshaman.github.io/ORMagic/)\n\n## Features and Roadmap\n\n<!--roadmap-start-->\n- [x] Define table schema using Pydantic models\n- [x] Basic CRUD operations\n - [x] Save data to the database\n - [x] Read data from the database\n - [x] Update data in the database\n - [x] Delete data from the database\n- [x] Relationships between tables\n - [x] One-to-many\n - [x] Create a tables with a foreign key\n - [x] Save data with a foreign key\n - [x] Read data with a foreign key\n - [x] Update data with a foreign key\n - [x] Delete data with a foreign key\n - [X] Cascade\n - [x] Set null\n - [x] Restrict\n - [x] Set default\n - [x] No action\n - [x] One-to-one\n - [x] Many-to-many\n- [x] Unique constraints\n- [x] Remove table\n- [x] Read all data from the database\n- [x] Filter data and retrieve multiple records\n - [x] Equal\n - [x] Not equal\n - [x] Greater than\n - [x] Greater than or equal\n - [x] Less than\n - [x] Less than or equal\n - [x] Like (Pattern matching with % and _)\n - [x] Not like (Pattern matching with % and _)\n - [x] In (List of values)\n - [x] Not in (List of values)\n - [x] Between (Two values)\n - [x] Not between (Two values)\n - [x] Q objects to combine filters (AND, OR, NOT)\n- [x] Protect against SQL injection\n- [x] Order by\n- [x] Limit and offset\n- [x] Update table schema\n - [x] Add new column\n - [x] Rename column\n - [x] Drop column\n- [x] Custom primary key\n- [x] Transactions\n- [x] Integration with databases\n - [x] SQLite\n - [x] PostgreSQL\n - [ ] MySQL\n- [ ] Functions\n - [ ] Aggregate functions\n - [ ] String functions\n - [ ] Date and time functions\n - [ ] Mathematical functions\n - [ ] Control flow functions\n- [ ] Migrations\n<!--roadmap-end-->\n\n## Changelog\n\n<!--changelog-start-->\nChanges for each release are thoroughly documented in [release notes](https://github.com/SpaceShaman/ORMagic/releases)\n<!--changelog-end-->\n\n## Contributing\n\n<!--contributing-start-->\nContributions are welcome! Feel free to open an issue or submit a pull request.\nI would like to keep the library to be safe as possible, so i would appreciate if you cover any new feature with tests to maintain 100% coverage.\n\n### Install in a development environment\n\n1. First, clone the repository:\n\n ```bash\n git clone git@github.com:SpaceShaman/ORMagic.git\n ```\n\n2. Install poetry if you don't have, here you can find the [instructions](https://python-poetry.org/docs/#installing-with-the-official-installer)\n\n3. Create a virtual environment and install the dependencies:\n\n ```bash\n cd ORMagic\n poetry install --no-root\n ```\n\n4. Activate the virtual environment:\n\n ```bash\n poetry shell\n ```\n\n### Run tests\n\nIf you in the virtual environment, you can run the tests with the following command:\n\n```bash\npytest\n```\n\nYou can also run the tests with coverage:\n\n```bash\npytest --cov=ormagic\n```\n\n<!--contributing-end-->\n\n## License\n\nThis project is licensed under the terms of the [MIT license](https://github.com/SpaceShaman/ORMagic?tab=MIT-1-ov-file)\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "ORMagic is a simple, fast, and lightweight ORM for Python, built on top of Pydantic.",
"version": "0.16.1",
"project_urls": {
"Documentation": "https://spaceshaman.github.io/ORMagic/",
"Homepage": "https://spaceshaman.github.io/ORMagic/",
"Repository": "https://github.com/SpaceShaman/ORMagic"
},
"split_keywords": [
"sql",
" orm",
" database",
" sqlite",
" db",
" sqlite3",
" pydantic",
" fastapi",
" postgresql",
" psycopg2",
" postgres"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "3e1b8b587d89f7604de8a9118c87359fec2cd8185eea510466392a9e7ae6d782",
"md5": "c323d0794783f5d76a060554a0f00732",
"sha256": "68d145f7bd8338668577d264f343ed3d0c024aefe66a2936bae81d311c10cee4"
},
"downloads": -1,
"filename": "ormagic-0.16.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c323d0794783f5d76a060554a0f00732",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.11",
"size": 14868,
"upload_time": "2025-01-12T10:23:34",
"upload_time_iso_8601": "2025-01-12T10:23:34.627018Z",
"url": "https://files.pythonhosted.org/packages/3e/1b/8b587d89f7604de8a9118c87359fec2cd8185eea510466392a9e7ae6d782/ormagic-0.16.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "565e809aa965f1e1e3871c6f9a3aedfbbd84fce916d90e17731668ad747d40cf",
"md5": "7366a6edcc2c97182abd9f450467fed1",
"sha256": "c987ebd8f9efe66d1390eac294bb6b7e3d78581fd21f0d65f898c5d97c68ed49"
},
"downloads": -1,
"filename": "ormagic-0.16.1.tar.gz",
"has_sig": false,
"md5_digest": "7366a6edcc2c97182abd9f450467fed1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.11",
"size": 12726,
"upload_time": "2025-01-12T10:23:38",
"upload_time_iso_8601": "2025-01-12T10:23:38.425627Z",
"url": "https://files.pythonhosted.org/packages/56/5e/809aa965f1e1e3871c6f9a3aedfbbd84fce916d90e17731668ad747d40cf/ormagic-0.16.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-12 10:23:38",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "SpaceShaman",
"github_project": "ORMagic",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "ormagic"
}