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

Installation

Install with pip:

pip install brunns-row

Or with uv:

uv add brunns-row

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.

Development

This project uses uv for dependency management and development.

Setup

# Install uv if you haven't already
curl -LsSf https://astral.sh/uv/install.sh | sh

# Clone and setup
git clone https://github.com/brunns/brunns-row.git
cd brunns-row
uv sync --all-extras

Common Commands

# Run tests
uv run pytest

# Run tests with coverage
uv run pytest --cov=src/brunns --cov-report=term-missing

# Format code
uv run ruff format .

# Lint
uv run ruff check .

# Type check
uv run mypy src/

# Build docs
uv run sphinx-build docs build_docs --color -W -bhtml

# Run all pre-commit checks
make precommit

For more options:

make help

Releasing

Releases are automated via GitHub Actions. To release a new version:

  1. Update the version number in pyproject.toml
  2. Run the pre-commit checks:
    make precommit
    
  3. Commit, tag, and push:
    git commit -am "chore: bump version to X.Y.Z"
    git push
    git tag vX.Y.Z
    git push --tags
    

The release workflow will automatically:

  • Run tests
  • Build the package
  • Publish to PyPI
  • Create a GitHub Release with release notes

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.1.tar.gz (75.6 kB view details)

Uploaded Source

Built Distribution

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

brunns_row-2.1.1-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file brunns_row-2.1.1.tar.gz.

File metadata

  • Download URL: brunns_row-2.1.1.tar.gz
  • Upload date:
  • Size: 75.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for brunns_row-2.1.1.tar.gz
Algorithm Hash digest
SHA256 1323680c0e24624fe87669e1682bda6995ca2e7e882983cd1c135074da284539
MD5 68219c320ffcf9f0cb6901770b43b496
BLAKE2b-256 cc08d5d841b5633cb114bb0cc67a87661e6ecde519a5af0de9e88c0972b5d33f

See more details on using hashes here.

Provenance

The following attestation bundles were made for brunns_row-2.1.1.tar.gz:

Publisher: release.yml on brunns/brunns-row

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: brunns_row-2.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for brunns_row-2.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 73f7660f279488c8927d2c9c5f6a6dfb990213508f2918f6ac3e0be4e43327a5
MD5 f5dc5081ac04186e589765f030156e67
BLAKE2b-256 762135c806398c0bb599d32be3a4604a73408e354d75c5c1186d746879382e16

See more details on using hashes here.

Provenance

The following attestation bundles were made for brunns_row-2.1.1-py3-none-any.whl:

Publisher: release.yml on brunns/brunns-row

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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