Skip to main content

Convenience wrapper for DB API and csv.DictReader rows, and similar.

Project description

brunns-row

Convenience wrapper for DB API and csv.DictReader rows, and similar, inspired by Greg Stein's lovely dtuple module.

made-with-python Build Status PyPi Version Python Versions Licence GitHub all releases GitHub forks GitHub stars GitHub watchers GitHub contributors GitHub issues GitHub issues-closed GitHub pull-requests GitHub pull-requests closed Codacy Badge Codacy Coverage Documentation Status Lines of Code

Setup

Install with pip:

pip install brunns-row

(As usual, use of a venv or virtualenv is recommended.)

Usage

The basic approach is to create a wrapper object from some kind of description - typically a DBAPI cursor's description, or a csv.DictReader's fieldnames attribute - then to use the wrapper's wrap(row) method to wrap each row. wrap(row) returns an object from which you can access the row's fields as attributes. A couple of simple examples:

DB API

cursor = conn.cursor()
cursor.execute("SELECT kind, rating FROM sausages ORDER BY rating DESC;")
wrapper = RowWrapper(cursor.description)
rows = [wrapper.wrap(row) for row in cursor.fetchall()]
for row in rows:
    print(row.kind, row.rating)

csv.DictReader

reader = csv.DictReader(csv_file)
wrapper = RowWrapper(reader.fieldnames)
rows = [wrapper.wrap(row) for row in reader]
for row in rows:
    print(row.kind, row.rating)

Attributes names are simply the column names where possible, converted to valid identifiers where necessary by replacing invalid characters with "_"s, prefixing any leading numerics with "a_", and de-duplicating where necessary by adding numeric suffixes.

Developing

Requires tox. Run make precommit tells you if you're OK to commit. For more options, run:

make help

Releasing

Requires hub, setuptools, wheel and twine. To release version n.n.n, first update the version number in setup.py, then:

version="n.n.n" # Needs to match new version number in setup.py.
git checkout -b "release-$version"
make precommit && git commit -am"Release $version" && git push --set-upstream origin "release-$version" # If not already all pushed, which it should be.
hub release create "V$version" -t"release-$version" -m"Version $version"
python setup.py sdist bdist_wheel
twine upload dist/*$version*
git checkout master
git merge "release-$version"

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

brunns-row-2.1.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

brunns_row-2.1.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file brunns-row-2.1.0.tar.gz.

File metadata

  • Download URL: brunns-row-2.1.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.7

File hashes

Hashes for brunns-row-2.1.0.tar.gz
Algorithm Hash digest
SHA256 70226ac5e2819fd472a2837b2db770c570ca11b2098996d503eedfaa75f679d7
MD5 db9754a8f88865d08ba205fd61a0effe
BLAKE2b-256 d92d1d219360c477f5abbed3dd4bca5aabddd9b7ab9e7a1c9b76c782754b9ba3

See more details on using hashes here.

File details

Details for the file brunns_row-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: brunns_row-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.7

File hashes

Hashes for brunns_row-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0953f231c812658a7cfd3240f1f6fac92e7b5bba247cfc22a4afa134f2a540f3
MD5 f1d9f7a2cdfad61539e100306f7525ce
BLAKE2b-256 ba5731cd6adb9ac92be4875ac0adb070acc32d29c6afbd5b0484873c7539495b

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