Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

180 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
make test

# Run tests with coverage
make coverage

# Format code
make format

# Lint
make lint

# Type check
make typecheck

# Build docs
make docs

# Run all pre-commit checks
make precommit

For more options:

make help

Releasing

Releases are automated via GitHub Actions. To release version n.n.n:

  1. Update version in pyproject.toml (using uv version --bump major|minor|patch) and docs/conf.py.
  2. Run make precommit to ensure all checks pass
  3. Commit and tag:
    version=`uv version --short`
    git pull -r
    git commit -am "Release v$version"
    git tag "v$version"
    git push origin master --tags

The GitHub Actions workflow will automatically:

  • Run tests and coverage checks
  • Build distribution packages
  • Publish to PyPI (using OIDC trusted publishing)
  • Create a GitHub release with auto-generated notes

About

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

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages