Skip to main content

pyrus-orm

Radically simple, django/peewee-like, easy and incomplete ORM for Pyrus.

With pyrus-orm, you can read, create and modify tasks.

Works with pyrus-api under the hood.

This is an early development version

Features:

  • Define models with:
    • simple fields (text, number, dates, checkmark, flag, ...)
    • catalog fields, single item
    • catalog fields, multiple items
    • "title" fields (pyrus-orm ignores the nested structure of 'title' fields, all its contents are treated as usual root-level fields)
    • multiple choice fields (without nested fields at this moment)
  • Operations with models:
    • Create and save
    • Read from registry by ID
    • Modify and save changes
  • Filtering:
    • by include_archived and steps fields
    • by value of simple or catalog fields
    • less than, greater than
    • value in a list
    • ranges

Installation

pip install pyrus-orm

Examples

Define model and initialize

class Book(PyrusModel):
    title = TextField(1)  # 1 is a field ID in pyrus's form
    time = TimeField(2)
    date = DateField(3)
    number = NumericField(4)
    round_number = IntegerField(5)
    author = CatalogField(6, catalog=<catalog id>)

    class Meta:
        form_id = <form_id>


pyrus_api = PyrusAPI(...)
session = PyrusORMSession(pyrus_api)

set_session_global(session)

Create item

book = Book(
    title='Don Quixote',
    date='1605-01-01',
    author=Book.author.find({'Name': 'Alonso Fernández de Avellaneda'})
)

book.save()

book.id
>>> <task_id>

Read and modify item

book = Book.objects.get(id=...)

# simple field
book.title
>>> 'Don Quixote'
book.title = 'Don Quixote, Part Two'
book.save('title changed')

# catalog field
book.author
>>> CatalogItem(item_id=..., values={'Name': 'Alonso Fernández de Avellaneda'})  # values comes from the catalog definition

book.author.find_and_set({'Name': 'Miguel de Cervantes'})  # may raise ValueError if no value found
book.save('changed an author to the real one')

Catalog Enum fields

Enums can be mapped to catalog items by ID or by custom property name.

Enums mapped to specific catalog items ID

No catalog lookups are preformed on reading or writing of such fields.

class Genre(Enum):
    fiction = 100001
    nonfiction = 100002


class Book(PyrusModel):
    genre = CatalogEnumField(<field_id>, catalog_id=<catalog_id>, enum=Genre, id_field='item_id')

book = Book.objects.get(id=...)

book.genre
>>> Genre.fiction

book.genre = Genre.nonfiction
book.save()

book.genre
>>> Genre.nonfiction

Enums mapped to catalog item properties

(imagine book has a property 'media' with field 'Name')

class Media(Enum):
    paper = 'paper'
    papirus = 'papirus'
    pdf = 'pdf'

class Book(PyrusModel):
    media = CatalogEnumField(<field_id>, catalog_id=<catalog_id>, enum=Genre, id_field='Name')

Filtering

Only basic filtering is supported:

Book.objects.get_filtered(
    title='Don Quixote',
)
>>> [Book(...), ...]


Book.objects.get_filtered(
    genre=Book.genre.find({'Name': 'Fiction'})
)
>>> [Book(...), ...]

Book.objects.get_filtered(
    ...
    include_archived=True,
    steps=[1, 2],
)
>>> [Book(...), ...]

Catalog fields, all the API

# Read values

# Non-empty value
book.author
>>> CatalogItem(item_id=..., values={<your custom values here>})

assert bool(book.author) == True

# Empty value
book.author
>>> CatalogEmptyValue()

assert bool(book.author) == False


# Get all possible values (works for empty fields as well)
book.author.catalog()
>>> [CatalogItem(...), CatalogItem(...), ...]


# Find a value in a catalog
new_author = book.author.catalog().find({'Name': 'Miguel de Cervantes'})
new_author
>>> CatalogItem(item_id=..., values={'Name': 'Miguel de Cervantes'})  # or None

book.author = new_author
book.save()


# Find and set shortcut
book.author.catalog().find_and_set({'Name': 'William Shakespeare'})

book.author.find_and_set({'Name': 'NonExistent'})
>>> ValueError raised


# Set value to a specific item_id
book.author = CatalogItem(item_id=123456)

Release files for pyrus-orm 0.0.11

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

Source distribution (sdist)

Source distribution for pyrus-orm 0.0.11
File Size Uploaded
pyrus_orm-0.0.11.tar.gz 13.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyrus-orm 0.0.11
File Interpreter ABI Platform
pyrus_orm-0.0.11-py3-none-any.whl Python 3 none any Details

Total release size: 27.1 kB

Release files / pyrus_orm-0.0.11.tar.gz

Download URL pyrus_orm-0.0.11.tar.gz
Size 13.4 kB
Tags Source
SHA-256 checksum
How to use checksums
690d78c3b025fbbb8dcee9ce784494a20f16946fef982b7853aa5d3e57376a5f
BLAKE2b-256 checksum
How to use checksums
08d61a4052a8583b3a2e0093053953d319196aee03a245f9daedd1fb62bc7b79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.2 CPython/3.11.1 Darwin/22.3.0

Release files / pyrus_orm-0.0.11-py3-none-any.whl

Download URL pyrus_orm-0.0.11-py3-none-any.whl
Size 13.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f0b5fc58dfde178618386672a84af9c1d95029fe2d222335639b57543b2b8ede
BLAKE2b-256 checksum
How to use checksums
34767a6d07b69c58397dab5c0f09fc6521a7974fa013a86211e65f6e12254e68
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.2 CPython/3.11.1 Darwin/22.3.0

Release history Release notifications | RSS feed

This release

0.0.11 This release

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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