Skip to main content

Context managers for secure and atomic database connectivity

Rationale

  • Each context being a single atomic process (“either all occur, or nothing occurs”)

  • No manual commit (success), rollback (fail) or close (either)

  • No ORM

Usage

Without Conntext,

conn = sqlite3.connect(":memory:")
try:
    cursor = conn.cursor()
    try:
        cursor.execute("CREATE TABLE person (name)")
        cursor.execute("INSERT INTO person (name) VALUES (?)",
                        ["microamp"])
    except Exception:
        raise
    finally:
        cursor.close()
except Exception:
    conn.rollback()
    raise
else:
    conn.commit()
finally:
    conn.close()

With Conntext,

from conntext import conntext

with conntext.conn(sqlite3.connect(":memory:")) as conn:
   with conntext.cursor(conn.cursor()) as cursor:
        cursor.execute("CREATE TABLE person (name)")
        cursor.execute("INSERT INTO person (name) VALUES (?)",
                       ["microamp"])

License

All the code is licensed under the GNU Lesser General Public License (v3+).

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Conntext-0.1.5.tar.gz (2.4 kB view details)

Uploaded Source

File details

Details for the file Conntext-0.1.5.tar.gz.

File metadata

  • Download URL: Conntext-0.1.5.tar.gz
  • Upload date:
  • Size: 2.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Conntext-0.1.5.tar.gz
Algorithm Hash digest
SHA256 f0c7b659bf1c10e4295dce766e2f1a45dfbcb593c87730ed5a861fd01932c653
MD5 58434ba67f3588692cd3677d2816fe2e
BLAKE2b-256 5e33e74939f6e453e032cb9b8c3089b3124fd91de771efaa8379bebb336e6b68

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.5 This release

1 file

0.1.4

1 file

0.1.3

1 file

0.1.2

1 file

0.1.1

1 file

0.1

1 file

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page