Skip to main content

Head First Python's Database Context Manager (updated for MariaDB)

Project description

Release 3 of DBcm

The DBcm.UseDatabase context manager for working with MySQL/MariaDB and SQLite3.

The 1.x release of this module was based on code created for the second edition of Head First Python. See chapters 7, 8, 9, and 11 of the that book for information on how this module was originally created. The 2.x and 3.x releases were updated during the writing of the third edition of the book.

Installation Notes

To install the second edition release of DBcm, please use:

pip install --upgrade DBcm=1.7.4

To install DBcm for use with a MySQL server (for example, on PythonAnywhere), please use:

pip install --upgrade DBcm=2.1

The 3.x release (the default install target) specifically works with the MariaDB server (for compatibility reasons).

The Latest (and Greatest) DBcm

For the third edition of Head First Python, DBcm moved to release 2. The option to use SQLite3 is now supported in this new release. Release 3 of DBcm removes the dependancy on mysql.connector and replaces it with (the more up-to-date) mariadb library (but do consider the Installation Notes, above).

Using DBcm

Simple example usage (for a MySQL/MariaDB backend):

from DBcm import UseDatabase, SQLError

config = { "host": "127.0.0.1",
           "user": "myUserid",
           "password": "myPassword",
           "database": "myDB" }

with UseDatabase(config) as cursor:
    try:
        _SQL = "select * from log"
        cursor.execute(_SQL)
        data = cursor.fetchall()
    except SQLError as err:
        print("Your query caused an issue:", str(err))

If a filename (string) is used in place of a config dictionary when using DBcm.UseDatabase, the data is assumed to reside in a local SQLite file (which gets created if it doesn't previously exist).

Project details


Download files

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

Source Distribution

dbcm-3.0.4.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

dbcm-3.0.4-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file dbcm-3.0.4.tar.gz.

File metadata

  • Download URL: dbcm-3.0.4.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.13.0

File hashes

Hashes for dbcm-3.0.4.tar.gz
Algorithm Hash digest
SHA256 787b87e77eb9b270e4feee50150dabd7a89b53da09fdb20aef1e5c738d637fcf
MD5 4f9fb121f7cc88e9d4a89a445f2eca5b
BLAKE2b-256 014496149a53412620562af66155748029c579f487351c7a0da7ab7bc798aae7

See more details on using hashes here.

File details

Details for the file dbcm-3.0.4-py3-none-any.whl.

File metadata

  • Download URL: dbcm-3.0.4-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.13.0

File hashes

Hashes for dbcm-3.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 04b424482796169fee40573d2e3f3f3dc64385b9e9d225738575e81d2410d2c4
MD5 7c418c4f3e586ca00c7aa89a23a4e1ea
BLAKE2b-256 b030de11df8232275719475b96cd129285c3f004031644c87befeda10ced209a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page