The `transaction` package provides a generic transaction implementation for Python, offering a two-phase commit protocol. It allows multiple backends (such as ZODB, SQLAlchemy, filesystem, or custom data managers) to participate in a single transaction, ensuring atomicity across diverse storage systems. It also supports savepoints, enabling partial rollbacks. The current version is 5.1, with a release cadence that has seen several major updates over the last few years, maintaining active development.
pip install transactionVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the basic pattern of using `transaction.commit()` and `transaction.abort()` within a try-except block. In a practical scenario, `some_backend_operation()` would involve one or more data managers (e.g., from ZODB, SQLAlchemy, or a custom implementation) that register themselves with the global transaction manager when modifications are made. The `transaction` library coordinates these data managers to ensure an all-or-nothing outcome using a two-phase commit protocol.
Ensure your Python environment meets the requirements of the `transaction` library version you are using. Upgrade Python to 3.10 or newer for `transaction` 5.1.
Migrate your code to use the modern transaction management APIs. Review the official documentation for the updated patterns for data manager integration and `TransactionManager.run` usage.
Be aware of thread boundaries. For scenarios requiring explicit transaction scope per request/task, consider using a framework integration (like `pyramid_tm`) or explicitly passing transaction objects, rather than relying solely on the global `transaction.manager` implicit behavior.
Perform irreversible side effects *after* a successful `transaction.commit()`. For blocking operations, restructure your code to move them outside the critical transaction path or use asynchronous patterns where appropriate.
Use `transaction.commit()` or `transaction.manager.commit()` to commit the active transaction. The `Transaction` object itself does not have a public `commit` method.
Ensure that `commit()` or `abort()` is called only once per transaction lifecycle, usually within a `try...except...finally` block to handle success or failure, or by using the `transaction.manager` as a context manager (`with transaction.manager:`).
Install the package using pip: `pip install transaction`
No dependency data recorded yet.