Skip to main content

psycopg2 integration with transaction

This package provides two-phase commit integration between psycopg2 and the transaction package.

Sample usage:

>>> import psycopg2, psycopg2transaction, transaction

>>> conn = psycopg2.connect(mydsn)
>>> trans = transaction.get()
>>> psycopg2transaction.join(conn, trans)

>>> ... do things with the psycopg2 connection

>>> transaction.commit()

This is just an example. The connection might come from a pool or otherwise already exist, as long as it is in a suitable state to start a distributed transaction.

Similarly, the transaction may come from the thread-local transaction manager, as shown above, or from an application-managed transaction manager.

The critical line in the example above is:

>>> psycopg2transaction.join(conn, trans)

The work done in the connection is committed by calling the transaction’s commit method, typically by calling commit on the transaction’s manager, as shown above.

If you use a thread-local transaction manager (as in the example above), you can omit the transaction argumet to join:

>>> psycopg2transaction.join(conn)

Connection management

Limited connection management is provided:

>>> dsn = 'dbname=test'
>>> conn = psycopg2transaction.join(dsn)
...
>>> conn = psycopg2transaction.join(dsn)
...
>>> transaction.commit()

If you pass a connection string rather than a connection to join, a connection will be opened for you and closed when the transaction is committed. If join is called multiple times with the same connection string, then the same connection is used and returned.

Using Postgres notify

You can’t use two-phase commit in postgres transactions in which you’ve used NOTIFY (or LISTEN or UNLISTEN). You can cause NOTIFY to be used after a transaction has committed, but before a managed connection has been closed by passing a notify argument to join with a name of a notification or a sequence of string notification named. The strings may be simple names, or names followed by a comma and string data, as would follow NOTIFY in a notify expression:

>>> conn = psycopg2transaction.join(dsn, notify='myjobs')

Changes

0.1.1 (2017-03-18)

  • Package meta data.

0.1.0 (2017-03-18)

Initial release

Metadata

Release files for psycopg2transaction 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for psycopg2transaction 0.1.1
File Size Uploaded Provenance Actions
psycopg2transaction-0.1.1.tar.gz 4.7 kB Without provenance Details for psycopg2transaction-0.1.1.tar.gz

Release files / psycopg2transaction-0.1.1.tar.gz

Download URL psycopg2transaction-0.1.1.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ffe007666c782860b09999eaf04e4b60d2045b80146a696be162dbb860a0d9ac
BLAKE2b-256 checksum
How to use checksums
39fc82d72616ee2974711fa5fb313a7198d5a38c087271b92ef3c878767c0f75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for psycopg2transaction 0.1.1

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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page