ORMagic


NameORMagic JSON
Version 0.15.0 PyPI version JSON
download
home_pagehttps://spaceshaman.github.io/ORMagic/
SummarySimple ORM based on Pydantic and SQLite with minimalistic API
upload_time2024-10-26 08:49:11
maintainerNone
docs_urlNone
authorSpaceShaman
requires_python<4.0,>=3.11
licenseMIT
keywords sql orm database sqlite db sqlite3 pydantic fastapi
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <picture>
  <source media="(prefers-color-scheme: dark)" srcset="docs/assets/logo-light.png">
  <img src="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)
[![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) database.

## 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
```

Or you can install the latest version from the GitHub repository:

```bash
git clone git@github.com:SpaceShaman/ORMagic.git
cd ORMagic
pip install .
```
<!--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
- [ ] Functions
    - [ ] Aggregate functions
    - [ ] String functions
    - [ ] Date and time functions
    - [ ] Mathematical functions
    - [ ] Control flow functions
- [ ] Migrations
- [ ] Integration with other databases
<!--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",
    "author": "SpaceShaman",
    "author_email": "spaceshaman@tuta.io",
    "download_url": "https://files.pythonhosted.org/packages/1c/ae/4d8375030a0ebf262cf134e23ff82819ee951a2760aa173d68e098e63485/ormagic-0.15.0.tar.gz",
    "platform": null,
    "description": "<picture>\n  <source media=\"(prefers-color-scheme: dark)\" srcset=\"docs/assets/logo-light.png\">\n  <img src=\"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[![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) database.\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\nOr you can install the latest version from the GitHub repository:\n\n```bash\ngit clone git@github.com:SpaceShaman/ORMagic.git\ncd ORMagic\npip install .\n```\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- [ ] Functions\n    - [ ] Aggregate functions\n    - [ ] String functions\n    - [ ] Date and time functions\n    - [ ] Mathematical functions\n    - [ ] Control flow functions\n- [ ] Migrations\n- [ ] Integration with other databases\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": "Simple ORM based on Pydantic and SQLite with minimalistic API",
    "version": "0.15.0",
    "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"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e6dbe241b481248a75c847f997efcd587c65b2914421baeec36f1a2de5da41d7",
                "md5": "0efcb8bd9a159693fd4de864904c8798",
                "sha256": "2206ad0f4efed97c3cee4943bbf21725c863935085b0e8e8e1544716de63b2c1"
            },
            "downloads": -1,
            "filename": "ormagic-0.15.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0efcb8bd9a159693fd4de864904c8798",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.11",
            "size": 12305,
            "upload_time": "2024-10-26T08:49:10",
            "upload_time_iso_8601": "2024-10-26T08:49:10.168051Z",
            "url": "https://files.pythonhosted.org/packages/e6/db/e241b481248a75c847f997efcd587c65b2914421baeec36f1a2de5da41d7/ormagic-0.15.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1cae4d8375030a0ebf262cf134e23ff82819ee951a2760aa173d68e098e63485",
                "md5": "c37a2d5127d7de57d9493adeb5f41a95",
                "sha256": "df4f5f221775980bc792a4d14463419362d4482227b11defc0704aaf01ae5b82"
            },
            "downloads": -1,
            "filename": "ormagic-0.15.0.tar.gz",
            "has_sig": false,
            "md5_digest": "c37a2d5127d7de57d9493adeb5f41a95",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.11",
            "size": 11635,
            "upload_time": "2024-10-26T08:49:11",
            "upload_time_iso_8601": "2024-10-26T08:49:11.652251Z",
            "url": "https://files.pythonhosted.org/packages/1c/ae/4d8375030a0ebf262cf134e23ff82819ee951a2760aa173d68e098e63485/ormagic-0.15.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-26 08:49:11",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "SpaceShaman",
    "github_project": "ORMagic",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "ormagic"
}
        
Elapsed time: 0.33764s