Registry / database / pony
library0.7.19pypypi✓ verified 87d ago

Pony ORM is a Python Object-Relational Mapper that allows developers to work with databases using Python objects and queries written in plain Python. It translates Python queries into optimized SQL, supporting SQLite, PostgreSQL, MySQL, and Oracle. The current version is 0.7.19. Releases occur periodically, often driven by new Python version support or significant bugfixes, indicating an active but not rapid development cadence with several months to a year between minor releases.

pip install pony
INSTALL
IMPORT
SIG · PONY
P
pony
databasepythonv0.7.19
Install
1.8s avg
Import
245ms
Disk
20MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.7.19 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.256s · 21.2MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.8s · import 0.233s · 22MB
20MB installed
● package 20MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Database
from pony.orm import Database
Required
from pony.orm import Required
Optional
from pony.orm import Optional
Set
from pony.orm import Set
PrimaryKey
from pony.orm import PrimaryKey
db_session
from pony.orm import db_session
select
from pony.orm import select

This quickstart demonstrates defining a database connection, creating entity models, generating the database schema, and performing basic CRUD operations within a `db_session` context. It uses an in-memory SQLite database for simplicity.

from pony.orm import * db = Database() class Person(db.Entity): id = PrimaryKey(int, auto=True) name = Required(str) age = Optional(int) cars = Set('Car') class Car(db.Entity): make = Required(str) model = Required(str) owner = Required(Person) db.bind(provider='sqlite', filename=':memory:', create_db=True) db.generate_mapping(create_tables=True) @db_session def create_data(): p1 = Person(name='John Doe', age=30) c1 = Car(make='Toyota', model='Camry', owner=p1) p2 = Person(name='Jane Smith', age=25) print("Data created.") @db_session def query_data(): for p in select(p for p in Person if p.age < 35): print(f"Name: {p.name}, Age: {p.age}") for car in p.cars: print(f" Car: {car.make} {car.model}") create_data() query_data()
Debug
Known issues
breakingPony ORM 0.7.17 dropped support for Python versions older than 3.8. Users on Python 3.7 or earlier must either upgrade their Python environment or use an older Pony ORM version (e.g., 0.7.16 or earlier).
fix
Upgrade Python to 3.8+ or pin Pony ORM to a compatible version.
affects: <0.7.17
breakingPony ORM versions prior to 0.7.15 were incompatible with Python 3.10+ due to reliance on the deprecated `parser` module. Attempting to use older versions on Python 3.10+ will result in import errors.
fix
Upgrade Pony ORM to version 0.7.15 or newer for Python 3.10 and above.
affects: <0.7.15
gotchaAll database operations (entity creation, updates, queries) must occur within an active `db_session`. Forgetting to use the `@db_session` decorator or `with db_session():` context manager will lead to `TransactionError` or `ObjectIsFreedException`.
fix
Always wrap database interactions within a `db_session`.
affects: All versions
gotchaPony ORM's unique query language uses generator expressions (e.g., `select(p for p in Person if p.age < 35)`). New users often try to use SQL strings or SQLAlchemy-style expressions, which will not work as expected.
fix
Familiarize yourself with Pony's Pythonic query syntax as described in the official documentation.
affects: All versions
Errors
Common errors & fixes
TransactionError: An attempt to work with detached object
Trying to access or modify Pony ORM entities outside of an active `db_session` context.
fix
Wrap your database operations within a `with db_session():` block or decorate functions with `@db_session`.
TypeError: DBAPIProvider.__init__() got multiple values for argument 'database'
An internal bug in Pony ORM versions prior to 0.7.16, specifically affecting `db.bind()` calls with certain argument combinations.
fix
Upgrade Pony ORM to version 0.7.16 or newer. This bug was resolved in that release.
OperationalError: (2013, 'Lost connection to MySQL server during query')
Network instability, database server restart, or connection timeouts for long-running processes that hold open connections.
fix
While Pony ORM includes some reconnection logic, ensure each logical unit of work is encapsulated within a `db_session`. For very long-running applications, consider explicit connection management or shorter `wait_timeout` on the database.
AttributeError: module 'pony.orm.parser' has no attribute 'suite'
Using Pony ORM older than 0.7.15 with Python 3.10+. Python 3.10 removed the `parser` module which older Pony versions relied upon.
fix
Upgrade Pony ORM to version 0.7.15 or newer, which transitioned to using Python's standard `ast` module.
Upgrade
Version history
0.7.19latest on PyPI · released Aug 27, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Resources
pony — pip install pony · libregistry