ORMagic is a simple, fast, and lightweight ORM for Python, built on top of Pydantic.
Project description
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 and PostgreSQL databases.
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
By default, ORMagic uses SQLite 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 you need to install psycopg2, you can do it with the following command:
pip install ORMagic[postgres]
Additionally, to use a database other than SQLite, you need to set the ORMAGIC_DATABASE_URL environment,
more information about that you can find in the documentation.
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
- One-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
- Transactions
- Integration with databases
- SQLite
- PostgreSQL
- MySQL
- Functions
- Aggregate functions
- String functions
- Date and time functions
- Mathematical functions
- Control flow functions
- Migrations
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
-
First, clone the repository:
git clone git@github.com:SpaceShaman/ORMagic.git
-
Install poetry if you don't have, here you can find the instructions
-
Create a virtual environment and install the dependencies:
cd ORMagic poetry install --no-root
-
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ormagic-0.16.1.tar.gz.
File metadata
- Download URL: ormagic-0.16.1.tar.gz
- Upload date:
- Size: 12.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.0.1 CPython/3.12.8 Linux/6.5.0-1025-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c987ebd8f9efe66d1390eac294bb6b7e3d78581fd21f0d65f898c5d97c68ed49
|
|
| MD5 |
7366a6edcc2c97182abd9f450467fed1
|
|
| BLAKE2b-256 |
565e809aa965f1e1e3871c6f9a3aedfbbd84fce916d90e17731668ad747d40cf
|
File details
Details for the file ormagic-0.16.1-py3-none-any.whl.
File metadata
- Download URL: ormagic-0.16.1-py3-none-any.whl
- Upload date:
- Size: 14.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.0.1 CPython/3.12.8 Linux/6.5.0-1025-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68d145f7bd8338668577d264f343ed3d0c024aefe66a2936bae81d311c10cee4
|
|
| MD5 |
c323d0794783f5d76a060554a0f00732
|
|
| BLAKE2b-256 |
3e1b8b587d89f7604de8a9118c87359fec2cd8185eea510466392a9e7ae6d782
|