Skip to main content

postmodel

Introduction

Postmodel is an easy-to-use asyncio ORM (Object Relational Mapper) inspired by Django and Tortoise ORM.

Postmodel provides 90% Django ORM like API, to ease the migration of developers wishing to switch to asyncio.

Currently, Postmodel provides following features:

  • full active-record pattern
  • optimistic locking
  • 100% code coverage

But, it still have some limits:

  • only support Postgresql
  • no planing support SQLite, instead it will supports RediSQL
  • no support relation

Postmodel is supported on CPython >= 3.6 for PostgreSQL.

Getting Started

Installation

You have to install postmodel like this:

pip install postmodel

Quick Tutorial

Primary entity of postmodel is postmodel.models.Model. You can start writing models like this:

from postmodel import models

class Book(models.Model):
    id = models.IntField(pk=True)
    name = models.TextField()
    tag = models.CharField(max_length=120)

    class Meta:
        table = "book_test"

    def __str__(self):
        return self.name

After you defined all your models, postmodel needs you to init them, in order to create backward relations between models and match your db client with appropriate models.

You can do it like this:

from postmodel import Postmodel

async def init():
    # Here we connect to a PostgreSQL DB.
    # also specify the app name of "models"
    # which contain models from "app.models"
    await Postmodel.init(
        'postgres://postgres@localhost:54320/test_db',
        modules= [__name__]
    )
    # Generate the schema
    await Postmodel.generate_schemas()

Here we create connection to Postgres database, and then we discover & initialise models.

Postmodel currently supports the following databases:

  • PostgreSQL (requires asyncpg)

generate_schema generates the schema on an empty database. Postmodel generates schemas in safe mode by default which includes the IF NOT EXISTS clause, so you may include it in your main code.

After that you can start using your models:

# Create instance by save
book = Book(id=1, name='Mastering postmdel', tag="orm")
await book.save()

# Or by .create()
await Book.create(id=2, name='Learning Python', tag="python")

# Query

books = await Book.filter(tag="orm").all()
assert len(books) == 1

Contributing

Please have a look at the Contribution Guide <docs/CONTRIBUTING.md>_

License

This project is licensed under the MIT License - see the LICENSE <LICENSE>_ file for details

Metadata

Release files for postmodel 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for postmodel 0.3.0
File Size Uploaded Provenance
postmodel-0.3.0.tar.gz 28.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for postmodel 0.3.0
File Interpreter ABI Platform
postmodel-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 59.6 kB

Release files / postmodel-0.3.0.tar.gz

Download URL postmodel-0.3.0.tar.gz
Size 28.0 kB
Tags Source
SHA-256 checksum
How to use checksums
52cbffd1327157bf8f930abf46df8d7ce8378588a7ac43109b4558fcffca331b
BLAKE2b-256 checksum
How to use checksums
940fd37eeb35cc33a70886e4bc5960046b69c3c0a34c8797d3456cfb5b3077b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.8

Release files / postmodel-0.3.0-py3-none-any.whl

Download URL postmodel-0.3.0-py3-none-any.whl
Size 31.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8b133b8d9cd987d576f6287c087b6d7d2f5fbd486949b8633dbf51e5e3bce8fd
BLAKE2b-256 checksum
How to use checksums
f85a3c451f7b04d238759a54460e6e8bbad958ec2425fc6c4cafc35b9b87c593
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.8

Security for postmodel 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page