Skip to main content

Simple ORM based on Pydantic and SQLite with minimalistic API

Project description

GitHub License Tests Codecov PyPI - Python Version PyPI - Version Code style: black Linting: Ruff Pydantic SQLite Pytest MkDocs-Material

The main goal of ORMagic is to provide a simple and easy-to-use ORM for Python, that is easy to understand and use, while still providing the necessary features to interact with a database. Is based on the Pydantic model and extends it with the ability to interact with SQLite database.

Simple example

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)

You can find more examples and detailed documentation at spaceshaman.github.io/ORMagic/

Installation

You can install ORMagic using pip:

pip install ORMagic

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

git clone git@github.com:SpaceShaman/ORMagic.git
cd ORMagic
pip install .

Documentation

The full documentation is available at spaceshaman.github.io/ORMagic/

Features and Roadmap

  • Define table schema using Pydantic models
  • Basic CRUD operations
    • Save data to the database
    • Read data from the database
    • Update data in the database
    • Delete data from the database
  • Relationships between tables
    • One-to-many
      • Create a tables with a foreign key
      • Save data with a foreign key
      • Read data with a foreign key
      • Update data with a foreign key
      • Delete data with a foreign key
        • Cascade
        • Set null
        • Restrict
        • Set default
        • No action
    • One-to-one
    • Many-to-many
  • Unique constraints
  • Remove table
  • Read all data from the database
  • Filter data and retrieve multiple records
    • Equal
    • Not equal
    • Greater than
    • Greater than or equal
    • Less than
    • Less than or equal
    • Like (Pattern matching with % and _)
    • Not like (Pattern matching with % and _)
    • In (List of values)
    • Not in (List of values)
    • Between (Two values)
    • Not between (Two values)
    • Q objects to combine filters (AND, OR, NOT)
  • Protect against SQL injection
  • Order by
  • Limit and offset
  • Update table schema
    • Add new column
    • Rename column
    • Drop column
  • Custom primary key
  • Functions
    • Aggregate functions
    • String functions
    • Date and time functions
    • Mathematical functions
    • Control flow functions
  • Bulk operations (save, update, delete)
  • Migrations
  • Integration with other databases

Changelog

Changes for each release are thoroughly documented in release notes

Contributing

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:

    git clone git@github.com:SpaceShaman/ORMagic.git
    
  2. Install poetry if you don't have, here you can find the instructions

  3. Create a virtual environment and install the dependencies:

    cd ORMagic
    poetry install --no-root
    
  4. Activate the virtual environment:

    poetry shell
    

Run tests

If you in the virtual environment, you can run the tests with the following command:

pytest

You can also run the tests with coverage:

pytest --cov=ormagic

License

This project is licensed under the terms of the MIT license

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ormagic-0.13.0.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

ormagic-0.13.0-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file ormagic-0.13.0.tar.gz.

File metadata

  • Download URL: ormagic-0.13.0.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.5.0-1025-azure

File hashes

Hashes for ormagic-0.13.0.tar.gz
Algorithm Hash digest
SHA256 47741b2aedaeffbcd6b23b2280d26a2f2f0b3c2fb7c99dce16133312468f9378
MD5 9b0e71b1f9e194d3992816c921a1e480
BLAKE2b-256 8445d5020bb3dfff1c3ce3c2a7aa26bb4fbbf2de0870222df2cf2e372a2f9bd9

See more details on using hashes here.

File details

Details for the file ormagic-0.13.0-py3-none-any.whl.

File metadata

  • Download URL: ormagic-0.13.0-py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.5.0-1025-azure

File hashes

Hashes for ormagic-0.13.0-py3-none-any.whl
Algorithm Hash digest
SHA256 145344df3ddca915da55c0129ecbcf43866b741d151624ed8e52959947bf1465
MD5 ed391807de9878727a560b7f3c5f01ee
BLAKE2b-256 f0b1d9b2d2628c846103a7e5e4968385adbc4eb0e93d4f1c726ed650aea5a40f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page