Skip to main content

Easy Python database interaction

Project description

easy_db

easy_db is a high-level Python library designed to simplify working with databases. The "DataBase" class handles connecting to various types of databases while providing simple methods for common tasks. The underlying database connection and cursor can be used when more precise control is desired.

Goals

  • Make common database tasks simple and easy
  • Intelligently handle different database types
  • Provide intuitive, consistent, Pythonic methods database interaction
  • Provide good performance without requiring polished query code
  • Expose database connection and cursor to users wanting fine-grained control
  • Just get the data into Python so we can use it!

Quick Start

Let's first connect to a SQLite database.

import easy_db
db = easy_db.DataBase('test_sqlite3_db.db')

Now let's see what tables are available in this database.

tables = db.table_names()

Table columns and types are simple to investigate.

print(db.columns_and_types('example_table'))

Let's pull all of the data from a table. We could start with something like "SELECT * ..." but this is way more fun:

data = db.pull_table('example_table')

Note that the table/query data is returned as a list of dictionaries with column names as dictionary keys.

  • Pro Tip: If desired, a Pandas dataframe of the same form as the database table can be easily created from this data structure using:
import pandas
df = pandas.DataFrame(data)

Now perhaps we have an Access database and would like to pull in a table from our SQLite database. easy_db makes this simple and gracefully handles the nuances of dealing with the different databases.

db = easy_db.DataBase('test_sqlite3_db.db')
db_2 = easy_db.DataBase('test_access_db.accdb')

db_2.copy_table(db, 'example_table')

The DataBase object can be used as a context manager for running custom SQL. The cursor is provided and the connection runs .commit() and .close() implicitly after the "while" block.

with db as cursor:
    cursor.execute('DELETE * FROM example_table;')

Thanks for checking out easy_db, and please take a look at the methods of the DataBase class if you'd like to see what other capabilities are available!

License

MIT

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

easy_db-0.8.2.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

easy_db-0.8.2-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file easy_db-0.8.2.tar.gz.

File metadata

  • Download URL: easy_db-0.8.2.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.0

File hashes

Hashes for easy_db-0.8.2.tar.gz
Algorithm Hash digest
SHA256 c41a36e9ac6ae16cf86a94320929ce782a8fda82d249d002282b71b3897ee2ec
MD5 4fb5f20857f767bbf4889c2567865f62
BLAKE2b-256 6af28cd9500472e5c1f5b6b8bc2a82e1284f2619d956e68450e0ae9375d112f7

See more details on using hashes here.

File details

Details for the file easy_db-0.8.2-py3-none-any.whl.

File metadata

  • Download URL: easy_db-0.8.2-py3-none-any.whl
  • Upload date:
  • Size: 14.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.0

File hashes

Hashes for easy_db-0.8.2-py3-none-any.whl
Algorithm Hash digest
SHA256 442084b3e0da188ca22763dd62556fc31a959b9f32b37cc45e47b56ec2b1d2c7
MD5 087004c0b4ac9ff228aae264ff30ee53
BLAKE2b-256 31eaacf623c24e05cb0f591f6e5be07a2eebb3c9c36ab7da534276c2081c444d

See more details on using hashes here.

Supported by

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