Skip to main content

Lightweight and simple ORM for Python (with psycopg)

Project description

Kirpi ORM

Lightweight and simple ORM library for Python(with psycopg)

Installation

pip install kirpi

Initialization

kirpi init

Write models

# models/user.py
from kirpi import types


class User(types.Model):
    id = types.Serial(primary_key=True, null=False)
    username = types.VarChar(max_len=20, unique=True)
    first_name = types.VarChar(max_len=20)
    last_name = types.VarChar(max_len=20)

User().create()

Write schemas

# schemas/user.py
from dataclasses import dataclass
from kirpi import Model
from models.user import User as user


@dataclass
class User(user, Model):
    id: int
    username: str
    first_name: str
    last_name: str

Usage models and schemas

# test.py
from schemas.user import User as UserSchema
from models.user import User

all_users = User.all(schema=UserSchema)
print(all_users)

get all objects Model.all()

# returns list of all users on page 1
users = User.all()

# returns list of all users on page 2
users_page_2 = User.all(page=2)

get objects with filter Model.filter()

# returns a list of all users whose first_name starts with Ali
User.filter(first_name_starts_with="Ali")

get one object Model.get()

# returns a user whose id is equal to 1 
User.get(id=1)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kirpi-1.0.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kirpi-1.0.0-py2.py3-none-any.whl (7.9 kB view details)

Uploaded Python 2Python 3

File details

Details for the file kirpi-1.0.0.tar.gz.

File metadata

  • Download URL: kirpi-1.0.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for kirpi-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f8a771670f5f84ab511ca833321fb8d80cb2b12a88ce0324c8d062ff1e8efa05
MD5 954d17bf5f96ad2acbcf83f380d2c8aa
BLAKE2b-256 030118885c3598936da9e76975d3e300c3d450cd4d02d02db2810ba491166016

See more details on using hashes here.

File details

Details for the file kirpi-1.0.0-py2.py3-none-any.whl.

File metadata

  • Download URL: kirpi-1.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for kirpi-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 7a2e8573bacaba7de96695abb96a06ea57e1752afacab55b4950fd1b94d94a2a
MD5 1ad0dcc6307f3d3c51a4c4a00d4a029f
BLAKE2b-256 0666b9f9f71f8cd77f868cbaf4da2a5cda98a2fe82103ad9fb1807a20720bfc1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page