Skip to main content

The DBcm library from Head First Python 2nd edition (ported to nbdev).

Reason this release was yanked:

Built with nbdev and I've done something wrong, so 1.7.2 is broken. Please use 1.7.1 for now.

Project description

DBcm

The Database Context Manager from the 2nd Edition of Head First Python.

Install

You can easily install DBcm into your local Python with this command:

pip install DBcm

Note: there is no conda install option at this time.

How to use

The UseDatabase context manager for working with MySQL/MariaDB.

For more information, see Chapters 7, 8, 9, and 11 of the 2nd edition of Head First Python.

Assumptions: you've installed either MySQL or MariaDB, created a database, granted a user full access to the database, and (optionally) created one of more tables within the database.

Begin by importing what you need from DBcm:

from DBcm import UseDatabase, SQLError

Then create a dictionary which provides your DB credentials data (substituting the relevant values as required):

config = { 'host': '127.0.0.1',
           'user': 'useridhere',
           'password': 'passwordhere',
           'database': 'dbnamehere',
         }

Use the config dictionary together with the UseDatabase context manager to interact with your database tables. Note: there's an assumption that already you know/understand some basic SQL here:

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

The result of the query is in the data variable.

Enjoy, and have fun. (Sorry: Python 3 only, due to type hints and new Exception syntax).

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-1.7.2.tar.gz (10.2 kB view hashes)

Uploaded Source

Built Distribution

DBcm-1.7.2-py3-none-any.whl (7.9 kB view hashes)

Uploaded Python 3

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