Skip to main content

FastORM framework, easy to learn, fast to code

Project description

FastORM

ORM for async postgres

Beta v0.0.2

FastORM is a modern, fast (async), database library for projects with Python 3.10+ based on standard Python type hints.

The key features are:

  • TBA

Example

See example.py for more examples.

Let's define some tables, to show off the capabilities.

class State(str, Enum):
    RUNNING = 'running'
    ABORTED = 'stopped'
    COMPLETED = 'done'
# end class


@dataclasses.dataclass
class User(FastORM):
    _ignored_fields = []
    _primary_keys = ['id']
    _automatic_fields = ['id']
    _table_name = 'user'

    id: Optional[int]  # Optional because automatically filled (_automatic_fields)
    name: str


@dataclasses.dataclass
class Auction(FastORM):
    _ignored_fields = []
    _primary_keys = ['id']
    _automatic_fields = ['id']
    _table_name = 'auction'

    id: Optional[int]  # Optional because automatically filled (_automatic_fields)
    owner: Union[int, User]  # can be provided by int or the native object
    previous_owner: Optional[User]  # Optional because nullable
    state: State  # Enum support :D
    title: str
    subtitle: Optional[str]  # nullable
    description: str
    start_date: datetime  # datetime support
    end_date: datetime
    metadata: JSONType
    deleted: bool
    chat_id: int

Now you can quickly write classes to the database:

conn = await FastORM.get_connection('postgresql://user:password@postgres_host/database')


user = User(id=None, name="hunter24")  # id will be filled by the database
await owner_user.insert(conn=conn)  # set's the id, too.

auction = Auction(
    id=None,  # gonna be automatic if `insert(…, ignore_setting_automatic_fields=False)` (default).
    # two ways of setting references to other tables:
    # by the actual value, in this case the numeric id
    owner=user.id,  
    # or via a different object,
    # it will use the id field (internally set by `User._primary_keys`) to determine the actual values.
    previous_owner=user,  
    state=State.RUNNING,  # enum will be a string in the database
    title="I sell my soul", subtitle="Slightly used",
    description="You only get a share though, others claim ownership, too.",
    start_date=datetime.now(), end_date=datetime.now() + timedelta(days=5),  # datetimes just works
    metadata={"just": ["json", "stuff", 111, datetime.now()]},  # will be native JSONB. You can have datetimes and your own classes in there as well, see `FastORM._set_up_connection`.
    deleted=False,
    chat_id=9223372036854775807,  # note, this database field must be BIGINT for such large numbers
)
await auction.insert(conn=conn)

Basic lookups are easy, too.

# single lookup, returns one element or None
user = await User.get(name="hunter24")
user = await User.get(id=1234)

# list of results (list can have length 0)
all_running_auctions = Auction.select(state=State.RUNNING)

Of course updating and deleting is possible too.

auction.state = State.COMPLETED
await auction.update()
await user.delete()

Download files

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

Source Distribution

fastorm-0.0.2.tar.gz (24.5 kB view details)

Uploaded Source

Built Distribution

fastorm-0.0.2-py3-none-any.whl (20.2 kB view details)

Uploaded Python 3

File details

Details for the file fastorm-0.0.2.tar.gz.

File metadata

  • Download URL: fastorm-0.0.2.tar.gz
  • Upload date:
  • Size: 24.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.26.0

File hashes

Hashes for fastorm-0.0.2.tar.gz
Algorithm Hash digest
SHA256 8188b38cce2732c19ddfb67f07fb7dc0397041271aaba422720f5780b837bf6b
MD5 3a9be19b18874aaf9374e3c68ff1d091
BLAKE2b-256 33eb72f9297418da7419e847be3f7e4b3b6f0c63a90a69ae7b3c40acfbf5c8c0

See more details on using hashes here.

File details

Details for the file fastorm-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: fastorm-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 20.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.26.0

File hashes

Hashes for fastorm-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 03b095e70672283310bf4e7a7a31ed72a5f900488e16611d7c1fab09e7c52896
MD5 0ea824e2e9d2cd5b9b12fe9ca94c4360
BLAKE2b-256 7f616f40092c23992eced1b89f9716117d8b30b6923991660be6281de091a2ba

See more details on using hashes here.

Supported by

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