New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

apgorm

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apgorm

A fully type-checked asynchronous ORM wrapped around asyncpg.

  • 1.0.0b14
  • PyPI
  • Socket score

Maintainers
1

apgorm

pypi codecov

Documentation | Support

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 tablename since 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.nicknames is a list of nicknames, it won't detect user.nicknames.append("new nick"). You need to do user.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()

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc