Skip to content

Releases: yezz123/ormdantic

1.0.0

22 Aug 19:34
0a717fd
Compare
Choose a tag to compare

Logo

Asynchronous ORM that uses pydantic models to represent database tables ✨

Ormdantic is a library for interacting with Asynchronous SQL databases from Python code, with Python objects. It is designed to be intuitive, easy to use, compatible, and robust.

Ormdantic is based on Pypika, and powered by Pydantic and SQLAlchemy, and Highly inspired by Sqlmodel, Created by @tiangolo.

What is Pypika?

PyPika is a Python API for building SQL queries. The motivation behind PyPika is to provide a simple interface for building SQL queries without limiting the flexibility of handwritten SQL. Designed with data analysis in mind, PyPika leverages the builder design pattern to construct queries to avoid messy string formatting and concatenation. It is also easily extended to take full advantage of specific features of SQL database vendors.

The key features are:

  • Easy to use: It has sensible defaults and does a lot of work underneath to simplify the code you write.
  • Compatible: It combines SQLAlchemy, Pydantic and Pypika tries to simplify the code you write as much as possible, allowing you to reduce the code duplication to a minimum, but while getting the best developer experience possible.
  • Extensible: You have all the power of SQLAlchemy and Pypika underneath.
  • Short Queries: You can write queries in a single line of code, and it will be converted to the appropriate syntax for the database you are using.

Requirements

A recent and currently supported version of Python (right now, Python supports versions 3.10 and above).

As Ormdantic is based on Pydantic and SQLAlchemy and Pypika, it requires them. They will be automatically installed when you install Ormdantic.

Installation

You can add Ormdantic in a few easy steps. First of all, install the dependency:

$ pip install ormdantic

---> 100%

Successfully installed Ormdantic
  • Install The specific Asynchronous ORM library for your database.
# MySQL
$ pip install ormdantic[mysql]

# PostgreSQL
$ pip install ormdantic[postgres]

# SQLite
$ pip install ormdantic[sqlite]

Example

To understand SQL, Sebastian the Creator of FastAPI and SQLModel created an amazing documentation that could help you understand the basics of SQL, ex. CREATE TABLE, INSERT, SELECT, UPDATE, DELETE, etc.

Check out the documentation.

But let's see how to use Ormdantic.

Create SQLAlchemy engine

Ormdantic uses SQLAlchemy under hood to run different queries, which is why we need to initialize by creating an asynchronous engine.

from sqlalchemy.ext.asyncio import create_async_engine as create_engine
from ormdantic import Ormdantic

engine = create_engine("sqlite+aiosqlite:///db.sqlite3")
database = Ormdantic(engine)

Note: You can use any asynchronous engine, check out the documentation for more information.