All Projects → zeaphoo → postmodel

zeaphoo / postmodel

Licence: MIT license
ORM library for Python 3.6+, asyncio. Provides Django ORM like API.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to postmodel

dvhb-hybrid
A package to mix django and asyncio in one application
Stars: ✭ 45 (+200%)
Mutual labels:  asyncio, asyncpg
sanic-url-shortener
Example of how to use Sanic and asyncpg (PostgreSQL)
Stars: ✭ 16 (+6.67%)
Mutual labels:  asyncio, asyncpg
Gino
GINO Is Not ORM - a Python asyncio ORM on SQLAlchemy core.
Stars: ✭ 2,299 (+15226.67%)
Mutual labels:  asyncio, asyncpg
aioredis-lock
Distributed locking implementation for aioredis
Stars: ✭ 20 (+33.33%)
Mutual labels:  asyncio
aioconnectors
Simple secure asynchronous message queue
Stars: ✭ 17 (+13.33%)
Mutual labels:  asyncio
nextion
Nextion serial client
Stars: ✭ 14 (-6.67%)
Mutual labels:  asyncio
aiotunnel
HTTP tunnel on top of aiohttp and asyncio
Stars: ✭ 29 (+93.33%)
Mutual labels:  asyncio
showdown-battle-bot
Socket Battle Bot for Pokemon Showdown (http://pokemonshowdown.com/)
Stars: ✭ 19 (+26.67%)
Mutual labels:  asyncio
asyncwhois
asyncio-compatible Python module for retrieving and parsing WHOIS information for any domain.
Stars: ✭ 26 (+73.33%)
Mutual labels:  asyncio
think-async
🌿 Exploring cooperative concurrency primitives in Python
Stars: ✭ 178 (+1086.67%)
Mutual labels:  asyncio
synchronicity
Synchronicity lets you interoperate with asynchronous Python APIs.
Stars: ✭ 41 (+173.33%)
Mutual labels:  asyncio
xsd to django model
Generate Django models from an XSD schema description (and a bunch of hints)
Stars: ✭ 20 (+33.33%)
Mutual labels:  django-orm
asyncio-socks-server
A SOCKS proxy server implemented with the powerful python cooperative concurrency framework asyncio.
Stars: ✭ 154 (+926.67%)
Mutual labels:  asyncio
helo
A simple and small low-level asynchronous ORM using Python asyncio.
Stars: ✭ 18 (+20%)
Mutual labels:  asyncio
nim-gatabase
Connection-Pooling Compile-Time ORM for Nim
Stars: ✭ 103 (+586.67%)
Mutual labels:  orm-framework
netunnel
A tool to create network tunnels over HTTP/S written in Python 3
Stars: ✭ 19 (+26.67%)
Mutual labels:  asyncio
fastapi-azure-auth
Easy and secure implementation of Azure AD for your FastAPI APIs 🔒 B2C, single- and multi-tenant support.
Stars: ✭ 174 (+1060%)
Mutual labels:  asyncio
rearq
A distributed task queue built with asyncio and redis, with built-in web interface
Stars: ✭ 81 (+440%)
Mutual labels:  asyncio
prisma-client-py
Prisma Client Python is an auto-generated and fully type-safe database client designed for ease of use
Stars: ✭ 739 (+4826.67%)
Mutual labels:  asyncio
glacier
❄️ Building Python CLI using docstrings and typehints 🐍
Stars: ✭ 84 (+460%)
Mutual labels:  asyncio

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].