Asynchronous ORM that uses pydantic models to represent database tables ✨

Overview

Logo

Asynchronous ORM that uses pydantic models to represent database tables

lint Test Package version

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.

Create a table

To create tables decorate a pydantic model with the database.table decorator, passing the database information ex. Primary key, foreign keys, Indexes, back_references, unique_constraints etc. to the decorator call.

from uuid import uuid4
from pydantic import BaseModel, Field

@database.table(pk="id", indexed=["name"])
class Flavor(BaseModel):
     """A coffee flavor."""

     id: UUID = Field(default_factory=uuid4)
     name: str = Field(max_length=63)

Queries

Now after we create the table, we can initialize the database with the table and then run different queries.

Init()

  • Register models as ORM models and initialize the database.

We use database.init will Populate relations information and create the tables.

async def main() -> None:
     await database.init()

Insert()

Now let's imagine we have another table called Coffee that has a foreign key to Flavor.

@database.table(pk="id")
class Coffee(BaseModel):
     """Drink it in the morning."""

     id: UUID = Field(default_factory=uuid4)
     sweetener: str | None = Field(max_length=63)
     sweetener_count: int | None = None
     flavor: Flavor

After we create the table, we can insert data into the table, using the database.insert method, is away we insert a Model Instance.

# Create a Flavor called "Vanilla"
vanilla = Flavor(name="Vanilla")

# Insert the Flavor into the database
await database[Flavor].insert(vanilla)

# Create a Coffee with the Vanilla Flavor
coffee = Coffee(sweetener="Sugar", sweetener_count=1, flavor=vanilla)

# Insert the Coffee into the database
await database[Coffee].insert(coffee)

Searching Queries

As we know, in SQL, we can search for data using different methods, ex. WHERE, LIKE, IN, BETWEEN, etc.

In Ormdantic, we can search for data using the database.find_one or database.find_many methods.

  • Find_one used to find a Model instance by Primary Key, its could also find with depth parameter.
     # Find one
     vanilla = await database[Flavor].find_one(flavor.id)
     print(vanilla.name)

     # Find one with depth.
     find_coffee = await database[Coffee].find_one(coffee.id, depth=1)
     print(find_coffee.flavor.name)
  • Find_many used to find Model instances by some condition ex. where, order_by, order, limit, offset, depth.
     # Find many
     await database[Flavor].find_many()

     # Get paginated results.
     await database[Flavor].find_many(
          where={"name": "vanilla"}, order_by=["id", "name"], limit=2, offset=2
     )

Update / Upsert Queries

Update

The modification of data that is already in the database is referred to as updating. You can update individual rows, all the rows in a table, or a subset of all rows. Each column can be updated separately; the other columns are not affected.

     # Update a Flavor
     flavor.name = "caramel"
     await database[Flavor].update(flavor)
Upsert

The Upsert method is similar to the Synchronize method with one exception; the Upsert method does not delete any records. The Upsert method will result in insert or update operations. If the record exists, it will be updated. If the record does not exist, it will be inserted.

     # Upsert a Flavor
     flavor.name = "mocha"
     await database[Flavor].upsert(flavor)

Delete

The DELETE statement is used to delete existing records in a table.

     # Delete a Flavor
     await database[Flavor].delete(flavor.id)

Development 🚧

Setup environment 📦

You should create a virtual environment and activate it:

python -m venv venv/
source venv/bin/activate

And then install the development dependencies:

# Install Flit
pip install flit

# Install dependencies
flit install --symlink

Run tests 🌝

You can run all the tests with:

bash scripts/test.sh

Note: You can also generate a coverage report with:

bash scripts/test_html.sh

Format the code 🍂

Execute the following command to apply pre-commit formatting:

bash scripts/format.sh

Execute the following command to apply mypy type checking:

bash scripts/lint.sh

License

This project is licensed under the terms of the MIT license.

Comments
  • ⬆ Bump jsmrcaga/action-netlify-deploy from 1.1.0 to 1.8.2

    ⬆ Bump jsmrcaga/action-netlify-deploy from 1.1.0 to 1.8.2

    Bumps jsmrcaga/action-netlify-deploy from 1.1.0 to 1.8.2.

    Release notes

    Sourced from jsmrcaga/action-netlify-deploy's releases.

    v1.8.2 - Fix multi-line GitHub output variables

    What's Changed

    New Contributors

    Full Changelog: https://github.com/jsmrcaga/action-netlify-deploy/compare/v1.8.1...v1.8.2

    v1.8.1 - GitHub warnings on setting output

    What's Changed

    New Contributors

    Full Changelog: https://github.com/jsmrcaga/action-netlify-deploy/compare/v1.8.0...v1.8.1

    v1.8.0 - Option to disable nvm

    What's Changed

    Full Changelog: https://github.com/jsmrcaga/action-netlify-deploy/compare/v1.7.2...v1.8.0

    v1.7.2 - Fix auto nvm

    What's Changed

    Full Changelog: https://github.com/jsmrcaga/action-netlify-deploy/compare/v1.7.1...v1.7.2

    v1.7.1 - Beta: Outputs

    What's Changed

    Full Changelog: https://github.com/jsmrcaga/action-netlify-deploy/compare/v1.7.0...v1.7.1

    v1.7.0 - Beta: Outputs

    What's Changed

    New Contributors

    Full Changelog: https://github.com/jsmrcaga/action-netlify-deploy/compare/v1.6.0...v1.7.0

    Beta

    ... (truncated)

    Commits
    • 4fcfeb8 fix: one liner to multi liner
    • d885259 fix: use one-liner syntax instead multi-liner
    • a3473e0 fix: use $GITHUB_OUTPUT instead set-output(deprecated)
    • 53de32e nvm: add option to disable nvm
    • fb6a5f9 Inputs: do not run nvm if not needed
    • 2fe02b2 Merge pull request #25 from tpluscode/patch-3
    • 9cc40dc feat: Add Netlify output as action outputs
    • 5689147 Merge branch 'master' into patch-3
    • 20cf18b chore: mention myself in readme
    • 97d9759 feat: add node version as input
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies github_actions 
    opened by dependabot[bot] 2
  • ⬆ Bump pypa/gh-action-pypi-publish from 1.5.1 to 1.5.2

    ⬆ Bump pypa/gh-action-pypi-publish from 1.5.1 to 1.5.2

    Bumps pypa/gh-action-pypi-publish from 1.5.1 to 1.5.2.

    Release notes

    Sourced from pypa/gh-action-pypi-publish's releases.

    v1.5.2

    What's Improved

    Full Diff: https://github.com/pypa/gh-action-pypi-publish/compare/v1.5.1...v1.5.2

    Commits
    • d7edd4c Add user-global site-packages to $PYTHONPATH
    • 8d5f27c Install Twine in the user-global site-packages
    • b0dc178 Disable pip cache dir with an env var
    • bbf6e0b Copy requirements to corresponding dir @ container
    • 0b69a8c Document broken pkginfo==1.9.0 transitive dep
    • c54db9c Integrate pip-tools-generated constraint files
    • 480ec4e Inherit yamllint config from the default preset
    • 5fb2f04 Drop __token__ from README code usage snippets
    • 7bbdccd Update the mention of master with unstable/v1
    • 328cf89 📝 Fix a link to the "Distribution Package" term
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies github_actions 
    opened by dependabot[bot] 2
  • fix: Improve field type translation

    fix: Improve field type translation

    Every subclass of the listed basic types is assumed to be meant to be translated to the corresponding SQLAlchemy types. Adds support for the Boolean, Date and DateTime types, fixes an issue where e.g. ConstrainedInt would be translated to JSON type, see #43 .

    Since this changes the database type for some python types, it might break code or lead to unexpected results when regenerating tables that were first created before this change.

    bug enhancement 
    opened by iron3oxide 2
  • Bump jsmrcaga/action-netlify-deploy from 1.1.0 to 1.8.0

    Bump jsmrcaga/action-netlify-deploy from 1.1.0 to 1.8.0

    Bumps jsmrcaga/action-netlify-deploy from 1.1.0 to 1.8.0.

    Release notes

    Sourced from jsmrcaga/action-netlify-deploy's releases.

    v1.8.0 - Option to disable nvm

    What's Changed

    Full Changelog: https://github.com/jsmrcaga/action-netlify-deploy/compare/v1.7.2...v1.8.0

    v1.7.2 - Fix auto nvm

    What's Changed

    Full Changelog: https://github.com/jsmrcaga/action-netlify-deploy/compare/v1.7.1...v1.7.2

    v1.7.1 - Beta: Outputs

    What's Changed

    Full Changelog: https://github.com/jsmrcaga/action-netlify-deploy/compare/v1.7.0...v1.7.1

    v1.7.0 - Beta: Outputs

    What's Changed

    New Contributors

    Full Changelog: https://github.com/jsmrcaga/action-netlify-deploy/compare/v1.6.0...v1.7.0

    Beta

    Changes

    Minor

    • Default install command is no longer npm i, it is inferred automatically from the .lock files

    Beta

    No release notes provided.

    Beta

    PRs

    Fixes

    Beta

    ... (truncated)

    Commits
    • 53de32e nvm: add option to disable nvm
    • fb6a5f9 Inputs: do not run nvm if not needed
    • 2fe02b2 Merge pull request #25 from tpluscode/patch-3
    • 9cc40dc feat: Add Netlify output as action outputs
    • 5689147 Merge branch 'master' into patch-3
    • 20cf18b chore: mention myself in readme
    • 97d9759 feat: add node version as input
    • aeb6aa5 docs: mention nvm
    • 9d9a0e5 Install node using nvm
    • 06b14e4 fix: fail action on script errors
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 2
  • Convert comparison to SQLModel to table and update claims

    Convert comparison to SQLModel to table and update claims

    I had to correct the claim that sqlmodel hasn't seen a release in a while. Also I converted the comparison into a table, which seems to be the more concise and natural format. I thought about adding a tgn file as a way to easily update the table on tablesgenerator.com, but reverted the commit as the markdown itself should be editable enough and less files are always preferable imho.

    documentation enhancement 
    opened by iron3oxide 2
  • ⬆ Bump pre-commit from 2.20.0 to 2.21.0

    ⬆ Bump pre-commit from 2.20.0 to 2.21.0

    Bumps pre-commit from 2.20.0 to 2.21.0.

    Release notes

    Sourced from pre-commit's releases.

    pre-commit v2.21.0

    Features

    Fixes

    Changelog

    Sourced from pre-commit's changelog.

    2.21.0 - 2022-12-25

    Features

    Fixes

    Commits
    • 40c5bda v2.21.0
    • bb27ea3 Merge pull request #2642 from rkm/fix/dotnet-nuget-config
    • c38e0c7 dotnet: ignore nuget source during tool install
    • bce513f Merge pull request #2641 from rkm/fix/dotnet-tool-prefix
    • e904628 fix dotnet hooks with prefixes
    • d7b8b12 Merge pull request #2646 from pre-commit/pre-commit-ci-update-config
    • 94b6178 [pre-commit.ci] pre-commit autoupdate
    • b474a83 Merge pull request #2643 from pre-commit/pre-commit-ci-update-config
    • a179808 [pre-commit.ci] pre-commit autoupdate
    • 3aa6206 Merge pull request #2605 from lorenzwalthert/r/fix-exe
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    Python dependencies 
    opened by dependabot[bot] 1
  • ✨ Support constrained lists

    ✨ Support constrained lists

    Concept

    In Python, a constrained list is a list that is restricted to contain only elements of a certain type or set of types. The Python package Pydantic includes a ConstrainedList class that can be used to define constrained lists in your code.

    Here is an example of how you might use the ConstrainedList class to define a constrained list of integers:

    from pydantic import ConstrainedList
    
    int_list = ConstrainedList(int, min_items=3, max_items=5)
    

    This creates a ConstrainedList object called int_list that can only contain integers and must have at least 3 items and at most 5 items.

    You can also use the ConstrainedList class to define a constrained list of elements that are instances of a particular class or that are of a particular subclass:

    from pydantic import ConstrainedList
    
    class Employee:
        def __init__(self, name: str, salary: int):
            self.name = name
            self.salary = salary
    
    employee_list = ConstrainedList(Employee)
    

    This creates a ConstrainedList object called employee_list that can only contain instances of the Employee class.

    The ConstrainedList class includes several other optional parameters that you can use to further constrain the elements of the list, such as min_items, max_items, and unique_items. You can find more information about the ConstrainedList class in the Pydantic documentation.

    Explanation

    The Feature starts by determining the target length of the list by calling a helper function called GetTargetLength, passing in the min_items and max_items attributes of the model_field object as arguments. It then initializes an empty list called items.

    The function then checks if type_ is a ConstrainedList object by checking if it is a subclass of pydantic.types.ConstrainedList. If it is, it sets the list_types variable to a tuple of the item types of the ConstrainedList object. If it is not, it sets list_types to the tuple of argument types of type_.

    The function then enters a loop that continues until the length of items is equal to the target length. Within the loop, it iterates over the items in list_types, and for each item, it calls a helper function called_get_value, passing in the item, the model_field object, and the use_default_values and optionals_use_none arguments. If the unique_items attribute of the model_field object is True and the value returned by _get_value is already in the items list, it continues to the next iteration of the loop. Otherwise, it appends the value to the items list.

    After the loop has been completed, the function returns the items list.

    enhancement Python 
    opened by yezz123 1
  • ✨ Added support for the `StrictInt` and `StrictFloat` types

    ✨ Added support for the `StrictInt` and `StrictFloat` types

    • Added support for the StrictInt and StrictFloat types from the strict-types library.
    • Added a strict_types flag to the generate function to control whether strict types are used for integers and floats.
    • Added unit tests for the new strict types and the strict_types flag.

    The StrictInt and StrictFloat types are subclasses of int and float, respectively, that provide additional validation for their values. They are used in the same way as the built-in int and float types, but will raise a TypeError if an invalid value is assigned to them.

    The strict_types flag is a boolean parameter added to the generate function. If strict_types is True, the _get_value function will use the StrictInt and StrictFloat types instead of int and float when generating random numbers.

    This pull request also includes unit tests for the new strict types and the strict_types flag to ensure that they are working as expected.

    enhancement refactoring 
    opened by yezz123 1
  • Introduce generator for Pydantic Model

    Introduce generator for Pydantic Model

    Usage

    Given a Pydantic model type can generate instances of that model with randomly generated values.

    Example

    from enum import auto, Enum
    from uuid import UUID
    
    from ormdantic.generator import Generator
    from pydantic import BaseModel
    
    
    class Flavor(Enum):
        MOCHA = auto()
        VANILLA = auto()
    
    
    class Brand(BaseModel):
        brand_name: str
    
    
    class Coffee(BaseModel):
        id: UUID
        description: str
        cream: bool
        sweetener: int
        flavor: Flavor
        brand: Brand
    
    
    print(Generator(Coffee))
    

    Result:

    id=UUID('93b517c2-083b-457d-a0e5-6e1bd2a927e4')
    description='ctWOb' cream=True sweetener=234
    flavor=<Flavor.VANILLA: 2> brand=Brand(brand_name='LMrIf')
    
    enhancement 
    opened by yezz123 1
  • ⬆ Bump pypa/gh-action-pypi-publish from 1.6.1 to 1.6.4

    ⬆ Bump pypa/gh-action-pypi-publish from 1.6.1 to 1.6.4

    Bumps pypa/gh-action-pypi-publish from 1.6.1 to 1.6.4.

    Release notes

    Sourced from pypa/gh-action-pypi-publish's releases.

    v1.6.4

    oh, boi! again?

    This is the last one tonight, promise! It fixes this embarrassing bug that was actually caught by the CI but got overlooked due to the lack of sleep. TL;DR GH passed $HOME from the external env into the container and that tricked the Python's site module to think that the home directory is elsewhere, adding non-existent paths to the env vars. See #115.

    Full Diff: https://github.com/pypa/gh-action-pypi-publish/compare/v1.6.3...v1.6.4

    v1.6.3

    Another Release!? Why?

    In pypa/gh-action-pypi-publish#112, it was discovered that passing a $PATH variable even breaks the shebang. So this version adds more safeguards to make sure it keeps working with a fully broken $PATH.

    Full Diff: https://github.com/pypa/gh-action-pypi-publish/compare/v1.6.2...v1.6.3

    v1.6.2

    What's Fixed

    • Made the $PATH and $PYTHONPATH environment variables resilient to broken values passed from the host runner environment, which previously allowed the users to accidentally break the container's internal runtime as reported in pypa/gh-action-pypi-publish#112

    Internal Maintenance Improvements

    New Contributors

    Full Diff: https://github.com/pypa/gh-action-pypi-publish/compare/v1.6.1...v1.6.2

    Commits
    • c7f29f7 🐛 Override $HOME in the container with /root
    • 644926c 🧪 Always run smoke testing in debug mode
    • e71a4a4 Add support for verbose bash execusion w/ $DEBUG
    • e56e821 🐛 Make id always available in twine-upload
    • c879b84 🐛 Use full path to bash in shebang
    • 57e7d53 🐛Ensure the default $PATH value is pre-loaded
    • ce291dc 🎨🐛Fix the branch @ pre-commit.ci badge links
    • 102d8ab 🐛 Rehardcode devpi port for GHA srv container
    • 3a9eaef 🐛Use different ports in/out of GHA containers
    • a01fa74 🐛 Use localhost @ GHA outside the containers
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies github_actions 
    opened by dependabot[bot] 1
  • ⬆ Bump pypa/gh-action-pypi-publish from 1.5.2 to 1.6.1

    ⬆ Bump pypa/gh-action-pypi-publish from 1.5.2 to 1.6.1

    Bumps pypa/gh-action-pypi-publish from 1.5.2 to 1.6.1.

    Release notes

    Sourced from pypa/gh-action-pypi-publish's releases.

    v1.6.1

    What's happened?!

    There was a sneaky bug in v1.6.0 which caused Twine to be outside the import path in the Python runtime. It is fixed in v1.6.1 by updating $PYTHONPATH to point to a correct location of the user-global site-packages/ directory.

    Full Diff: https://github.com/pypa/gh-action-pypi-publish/compare/v1.6.0...v1.6.1

    v1.6.0

    Anything's changed?

    The only update is that the Python runtime has been upgraded from 3.9 to 3.11. There are no functional changes in this release.

    Full Changelog: https://github.com/pypa/gh-action-pypi-publish/compare/v1.5.2...v1.6.0

    Commits
    • 5d1679f Use py3.11 user-global site-packages in PYTHONPATH
    • d2a2496 Switch the runtime from Python 3.9 to Python 3.11
    • See full diff in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies github_actions 
    opened by dependabot[bot] 1
Releases(1.5.0)
  • 1.5.0(Dec 15, 2022)

    What's Changed

    • Introduce generator for Pydantic Model by @yezz123 in https://github.com/yezz123/ormdantic/pull/73

    Usage

    Given a Pydantic model type can generate instances of that model with randomly generated values.

    Example

    from enum import auto, Enum
    from uuid import UUID
    
    from ormdantic.generator import Generator
    from pydantic import BaseModel
    
    
    class Flavor(Enum):
        MOCHA = auto()
        VANILLA = auto()
    
    
    class Brand(BaseModel):
        brand_name: str
    
    
    class Coffee(BaseModel):
        id: UUID
        description: str
        cream: bool
        sweetener: int
        flavor: Flavor
        brand: Brand
    
    
    print(Generator(Coffee))
    
    • Result:
    id=UUID('93b517c2-083b-457d-a0e5-6e1bd2a927e4')
    description='ctWOb' cream=True sweetener=234
    flavor=<Flavor.VANILLA: 2> brand=Brand(brand_name='LMrIf')
    

    Internal

    • ⬆ Bump pymdown-extensions from 9.7 to 9.8 by @dependabot in https://github.com/yezz123/ormdantic/pull/61
    • ⬆ Bump mypy from 0.982 to 0.990 by @dependabot in https://github.com/yezz123/ormdantic/pull/62
    • ⬆ Bump pytest-asyncio from 0.20.1 to 0.20.2 by @dependabot in https://github.com/yezz123/ormdantic/pull/63
    • ⬆ Bump mypy from 0.990 to 0.991 by @dependabot in https://github.com/yezz123/ormdantic/pull/64
    • ⬆ Bump pymdown-extensions from 9.8 to 9.9 by @dependabot in https://github.com/yezz123/ormdantic/pull/66
    • ⬆ Bump markdown-include from 0.7.0 to 0.8.0 by @dependabot in https://github.com/yezz123/ormdantic/pull/65
    • ⬆ Bump pypa/gh-action-pypi-publish from 1.5.1 to 1.5.2 by @dependabot in https://github.com/yezz123/ormdantic/pull/67
    • ⬆ Bump pypa/gh-action-pypi-publish from 1.5.2 to 1.6.1 by @dependabot in https://github.com/yezz123/ormdantic/pull/69
    • ⬆ Bump pypa/gh-action-pypi-publish from 1.6.1 to 1.6.4 by @dependabot in https://github.com/yezz123/ormdantic/pull/70
    • ⬆ Bump pytest-asyncio from 0.20.2 to 0.20.3 by @dependabot in https://github.com/yezz123/ormdantic/pull/71

    Full Changelog: https://github.com/yezz123/ormdantic/compare/1.4.1...1.5.0

    Source code(tar.gz)
    Source code(zip)
  • 1.4.1(Nov 6, 2022)

    • Support Python 3.11, and add it to classifiers.

    What's Changed

    • ⬆ Bump pytest-asyncio from 0.18.3 to 0.20.1 by @dependabot in https://github.com/yezz123/ormdantic/pull/56
    • ⬆ Bump pre-commit from 2.19.0 to 2.20.0 by @dependabot in https://github.com/yezz123/ormdantic/pull/57
    • ⬆ Bump mkdocs-mermaid2-plugin from 0.5.2 to 0.6.0 by @dependabot in https://github.com/yezz123/ormdantic/pull/58
    • ⬆ Bump pymdown-extensions from 9.1 to 9.7 by @dependabot in https://github.com/yezz123/ormdantic/pull/59
    • ⬆ Bump pytest-cov from 3.0.0 to 4.0.0 by @dependabot in https://github.com/yezz123/ormdantic/pull/60

    New Contributors

    • @dependabot made their first contribution in https://github.com/yezz123/ormdantic/pull/56

    Full Changelog: https://github.com/yezz123/ormdantic/compare/1.4.0...1.4.1

    Source code(tar.gz)
    Source code(zip)
  • 1.4.0(Oct 21, 2022)

    What's Changed

    Count

    To count the number of rows of a table or in a result set you can use the count function.

         # Count
         count = await database[Flavor].count()
         print(count)
    
    • It's support also Where and Depth
         count_advanced = await database[Coffee].count(
              where={"sweetener": 2}, depth=1
         )
         print(count_advanced)
    
    • :green_heart: Support Python 3.11 by @yezz123 in https://github.com/yezz123/ormdantic/pull/42
    • fix: Improve field type translation by @iron3oxide in https://github.com/yezz123/ormdantic/pull/44
    • ✨ Introduce the count() Feature by @yezz123 in https://github.com/yezz123/ormdantic/pull/50

    Full Changelog: https://github.com/yezz123/ormdantic/compare/1.3.0...1.4.0

    Source code(tar.gz)
    Source code(zip)
  • 1.3.0(Sep 17, 2022)

    What's Changed

    • Docs: Build Documentation for Ormdantic by @yezz123 in https://github.com/yezz123/ormdantic/pull/23
    • docs: Update FAQ by @iron3oxide in https://github.com/yezz123/ormdantic/pull/26
    • Convert comparison to SQLModel to table and update claims by @iron3oxide in https://github.com/yezz123/ormdantic/pull/27
    • Fix code block format in comparison table by @iron3oxide in https://github.com/yezz123/ormdantic/pull/28
    • Refactoring: Improve the Generator for Both Crud & Table Classes by @yezz123 in https://github.com/yezz123/ormdantic/pull/29
    • 👷🏻 Add Integration Integrations Tests by @yezz123 in https://github.com/yezz123/ormdantic/pull/36
    • :green_heart: Migrate to Hatchling by @yezz123 in https://github.com/yezz123/ormdantic/pull/38

    New Contributors

    • @iron3oxide made their first contribution in https://github.com/yezz123/ormdantic/pull/26

    Full Changelog: https://github.com/yezz123/ormdantic/compare/1.2.0...1.3.0

    Source code(tar.gz)
    Source code(zip)
  • 1.2.0(Aug 26, 2022)

    What's Changed

    • ✨ chore(fix): Ormdantic takes connection str instead of engine by @yezz123 in https://github.com/yezz123/ormdantic/pull/18

    Full Changelog: https://github.com/yezz123/ormdantic/compare/1.1.0...1.2.0

    Source code(tar.gz)
    Source code(zip)
  • 1.1.0(Aug 22, 2022)

    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 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.

    What's Changed

    • Chore(feat): Improve many to many relationships & add New tests by @yezz123 in https://github.com/yezz123/ormdantic/pull/15

    Full Changelog: https://github.com/yezz123/ormdantic/compare/1.0.0...1.1.0

    Source code(tar.gz)
    Source code(zip)
  • 1.0.0(Aug 22, 2022)

    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.

    Source code(tar.gz)
    Source code(zip)
Owner
Yasser Tahiri
API / Backend Engineer who speaks @python. Creator of @BnademOverflow. I love Open Source & Ancient Greece.
Yasser Tahiri
Pydastic is an elasticsearch python ORM based on Pydantic

Pydastic is an elasticsearch python ORM based on Pydantic. ?? Installation Pip: pip install pydastic Poetry: poetry add pydastic ?? Core Feat

Rami Awar 92 Dec 24, 2022
SQLAlchemy-Database provides shortcut functions to common database operations for SQLAlchemy ORM.

简体中文 | English SQLAlchemy-Database SQLAlchemy-Database provides shortcut functions to common database operations for SQLAlchemy ORM. Introduction Supp

AmisAdmin 5 Nov 28, 2022
This is a project template which uses FastAPI, Alembic and async SQLModel as ORM. It shows a complete async CRUD using authentication.

Async configuration for FastAPI and SQLModel This is a project template which uses FastAPI, Alembic and async SQLModel as ORM. It shows a complete asy

Jonathan Vargas 217 Dec 29, 2022
An addon package to transform/map dictionaries to Pydantic Models.

Pydantic Model Parser A simple package to transform/map dictionaries, before parsing it into Pydantic. Requirements The models/entities should conform

Goh Chun Teck 1 May 29, 2022
Easy generating ElasticSearch mappings based on ORM's models.

ElasticMapper ElasticSearch mapper for three ORMs - SQLAlchemy, Peewee, DjangoORM. Allows you to easily generate ElasticSearch mappings based on model

Polina 9 Jan 3, 2023
🪛 A simple pydantic to Form FastAPI model converter.

pyfa-converter Makes it pretty easy to create a model based on Field [pydantic] and use the model for www-form-data. How to simplify your life? What d

null 22 Jan 8, 2023
ODM (Object Document Mapper) for Elasticsearch based on Elasticsearch_dsl and Pydantic

es_odm ODM (Object Document Mapper) for Elasticsearch based on Elasticsearch_dsl and Pydantic. It's also a bridge connecting Mysql and Elasticsearch w

null 37 Sep 1, 2022
Use pydantic schemas to define your query parameters, with extra sugar in them ✨

FastAPI Query Parameters Empower your query parameters setup on FastAPI through Pydantic Installation poetry add fastapi-qp Usage You can just define

Clicampo 36 Nov 21, 2022
A project template where PyTorch Lightning, Pydantic, and more! being used for training MNIST as an example.

Deep Learning Project Template This template of a deep learning project where we are using the following PyTorch Lightning, Pydantic and much more! Se

Mazen 13 Dec 6, 2022
Generator of python HTTP-clients from OpenAPI specification based on httpx and pydantic

Pythogen Generator of python HTTP-clients from OpenApi specification based on httpx and pydantic. Features Discriminator Sync and async clients Tracin

Artur Smolin 38 Dec 26, 2022
msaFilesystem - Agnostic Abstract Filesystem API which allows to use S3, GCS, Azure Datalake, your local FS, Youtube etc Optimized for use with FastAPI/Pydantic.

msaFilesystem - Agnostic Abstract Filesystem API which allows to use S3, GCS, Azure Datalake, your local FS, Youtube etc Optimized for use with FastAP

Stefan Welcker 3 Nov 27, 2022
msaServer - Helper & Wrapper around Uvicorn/Gunicorn for FastAPI based apps Optimized for use with FastAPI/Pydantic.

msaServer - Helper & Wrapper around Uvicorn/Gunicorn for FastAPI based apps Optimized for use with FastAPI/Pydantic. Documentation: msaServer Document

Stefan Welcker 3 Nov 1, 2022
JWT Authentication with simple jwt. Uses Refresh token and Access tokens. Uses Blacklisting refresh token to logout.

Django JWT authentication with simple jwt (Refresh and Access tokens) This is a boiler plate code to get started with Django authentication. This proj

Rishab Bahal 2 Dec 2, 2022
A python tool using XGboost and sentence-transformers to perform schema matching task on tables.

Python Schema Matching by XGboost and Sentence-Transformers A python tool using XGboost and sentence-transformers to perform schema matching task on t

fireindark707 10 Oct 26, 2022
A python tool using XGboost and sentence-transformers to perform schema matching task on tables.

Python Schema Matching by XGboost and Sentence-Transformers A python tool using XGboost and sentence-transformers to perform schema matching task on t

fireindark707 3 Apr 13, 2022
Non Fungible Data, transform json non trustable data into columnar tables easily

What is NFD? (WIP) NOTE: I use 'Fungible' as a synonym of 'Trustable' cause no body knows what it really means. Many times we deal with json data that

Jose Angel Sanchez Castillejos 5 May 20, 2022
A package that with implementation of famous Pandas library in my way , allows you to visualize data using data tables

Pandas Prototype Love torturing data ? Cause if you torture the data it will confess! Feel the data talking to you #AliveData. A package with implemen

null 1 May 27, 2022
Create simple Latex tables.

latextable-lite Latextable-lite is a Python package that can create simple Latex tables. It is heavily based on Latextable, but removes latextable's d

null 6 Nov 9, 2022