Skip to main content

Expose existing dictionary fields as readable Python attributes.

Project description

SchemaBind

SchemaBind reduces repetitive dictionary lookup boilerplate by exposing existing fields as readable Python attributes.

Instead of:

first_name = row["first_name"]
email = row["email_address"]
phone = row.get("phone_number")

Use:

from schemabind import bind

customer = bind(row)

customer.first_name
customer.email_address
customer.phone_number

SchemaBind is currently focused on dictionaries, including rows produced by csv.DictReader.

It does not create schemas, validate data, transform values, or infer new fields. It simply provides a cleaner way to access fields that already exist.

Example

import csv
from schemabind import bind

with open("samples/csv/customer.csv") as f:
    rows = list(csv.DictReader(f))

customer = bind(rows[0])

print(customer.first_name)
print(customer.email_address)
print(customer.phone_number)

Missing attributes raise AttributeError instead of silently returning None, which helps catch typos in field names.

Field Normalization

SchemaBind supports simple field-name normalization for attribute access.

For example:

customer = bind({"First Name": "Kaladin"})

print(customer.first_name)

The original dictionary keys are preserved for dictionary-style helpers:

customer.keys()
customer.get("First Name")

If multiple fields normalize to the same attribute name, SchemaBind raises ValueError instead of guessing which field to use.

For example:

bind({
    "First Name": "Dalinar",
    "first_name": "Shallan",
})

Both fields would normalize to first_name, so the binding is rejected as ambiguous.

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

schemabind-0.1.0.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

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

schemabind-0.1.0-py3-none-any.whl (2.8 kB view details)

Uploaded Python 3

File details

Details for the file schemabind-0.1.0.tar.gz.

File metadata

  • Download URL: schemabind-0.1.0.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for schemabind-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fdff6a5ff22439fface8e6b09af82ccd8c54be298699e557d2873617734574a5
MD5 2fb5caaf2789ca6454db8ec2180a0bd8
BLAKE2b-256 f19e10e7cd512379d58f53f4baf931fc1de63b2492cc72f906cf33932607cf83

See more details on using hashes here.

File details

Details for the file schemabind-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: schemabind-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 2.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for schemabind-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7646e66244b51a0634e6ca07816dd59160d1d462a93dd4cd0dec1e440539fcfe
MD5 27d88635e6c630ae389b644c006462a1
BLAKE2b-256 70972b2c363a6f458d7116c8c80074e4442ce00695aac361c7eda3174809d1b2

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