A fully type-checked asynchronous ORM wrapped around asyncpg.
Project description
apgorm
An asynchronous ORM wrapped around asyncpg. Examples can be found under examples/. Run examples with python -m examples.<example_name> (python -m examples.basic).
Please note that this library is not for those learning SQL or Postgres. Although the basic usage of apgorm is straightforward, you will run into problems, especially with migrations, if you don't understand regular SQL well.
Features
- Fairly straightforward and easy-to-use.
- Support for basic migrations.
- Protects against SQL-injection.
- Python-side converters and validators.
- Decent many-to-many support.
- Fully type-checked.
- Tested.
Limitations
- Limited column namespace. For example, you cannot have a column named
tablenamesince that is used to store the name of the model. - Only supports PostgreSQL with asyncpg.
- Migrations don't natively support field/table renaming or type changes, but you can still write your own migration with raw SQL.
- Converters only work on instances of models and when initializing the model.
- Models can only detect assignments. If
User.nicknamesis a list of nicknames, it won't detectuser.nicknames.append("new nick"). You need to douser.nicknames = user.nicknames + ["new nick"].
Basic Usage
Defining a model and database:
class User(apgorm.Model):
username = apgorm.types.VarChar(32).field()
email = apgorm.types.VarChar().nullablefield()
primary_key = (username,)
class Database(apgorm.Database):
users = User
Intializing the database:
db = Database(migrations_folder="path/to/migrations")
await db.connect(database="database name")
Creating & Applying migrations:
if db.must_create_migrations():
db.create_migrations()
if await db.must_apply_migrations():
await db.apply_migrations()
Basic create, fetch, update, and delete:
user = await User(username="Circuit").create()
print("Created user", user)
assert user == await User.fetch(username="Circuit")
user.email = "email@example.com"
await user.save()
await user.delete()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file apgorm-1.0.0b14.tar.gz.
File metadata
- Download URL: apgorm-1.0.0b14.tar.gz
- Upload date:
- Size: 32.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.8.14 Linux/5.15.0-1022-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5fa4ede90b97c11bd59a36c198d6f5df0efbbc25695d88a89bd05c5ec65da214
|
|
| MD5 |
a617804dbbeb3c3b9e9c8f787121964a
|
|
| BLAKE2b-256 |
d30654c6c95a62d52d7305ac963d74e03a53854ba0e4fc884c0054334a495c5c
|
File details
Details for the file apgorm-1.0.0b14-py3-none-any.whl.
File metadata
- Download URL: apgorm-1.0.0b14-py3-none-any.whl
- Upload date:
- Size: 46.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.8.14 Linux/5.15.0-1022-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3086b04ff8e99342932b09856007d94ead4f46f025ae4a74ee01fcfcbb260c98
|
|
| MD5 |
fe60436358d2362a22a85fcebbb2cac6
|
|
| BLAKE2b-256 |
175534f2162f2d16e247d530eb41fcc300c8109fdbf5ae253ae7f8b1a7578eff
|