FastORM
ORM for async postgres
Beta
FastORM is a modern, fast (async), database library for projects with Python 3.10+ based on standard Python type hints.
The key features are:
- Async postgres
- Tested to work with Python 3.10
Install
pip install fastorm
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
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
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.create_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()
Metadata
Release files for fastorm 0.0.17
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fastorm-0.0.17.tar.gz | 74.3 kB | Without provenance | Details for fastorm-0.0.17.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fastorm-0.0.17-py3-none-any.whl | Python 3 | none | any | Details for fastorm-0.0.17-py3-none-any.whl |
Total release size: 120.3 kB
Release files / fastorm-0.0.17.tar.gz
| Download URL | fastorm-0.0.17.tar.gz |
|---|---|
| Size | 74.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cc4f7326e4837472f245668b04f7c81e191a22187a68caca06266cfc1ffc5c31
|
|
BLAKE2b-256 checksum How to use checksums |
eb9fe19e3377060bfc5a61ed324a64201d4baa9dbba17e5e1333a3f1703ea698
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.32.3
|
Release files / fastorm-0.0.17-py3-none-any.whl
| Download URL | fastorm-0.0.17-py3-none-any.whl |
|---|---|
| Size | 46.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9699c8c79fdd8b3aa4f2f23cbc3eb2ca727cec534e029489031ab598f7105019
|
|
BLAKE2b-256 checksum How to use checksums |
7016ab268ea371f30fdbf6b15eba363e1595e7a70af56fe7d4709d7288ad5e70
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.32.3
|
Security for fastorm 0.0.17
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.