Skip to main content

namedtuple-table

Problem

  • You want to make a "sample table" config file (e.g. for Snakemake), so that various system-specific attributes can be accessed via an index.
  • You want to store it as a human-readable tab-separated text file.
  • You don't want to install Pandas.

Solution

  • NamedTupleTable represents tabular data as a mapping between some index column and rows of some NamedTuple.

    my_table["label_1"] -> ThisTableNamedTuple
    
  • To index on a different column, produce a new table by calling .with_index("new_index"). Values of the new index must be unique in every row.

  • Tables are immutable and hashable, so should play nicely with caching, filters etc. We could add a "select" method etc. but it should be straightforward to do this stuff with Python's functional programming features.

Drawbacks

  • This is not designed to scale; in the intended use-case the table size is modest and you are doing somewhat expensive things with the data. If you need performance/scale, consider Pandas or a database interface like dataset.

Usage example

Store data in a tab-separated variable file. The first non-comment line must be a set of column headers. Other lines can be commented out with # or !

# dogs.tsv
ref	name		collar	age
1	Bertie		red	4
2	Geoff		blue	2
!3	Bandit		none	40
4	Gertrude	blue	5

and load with

>>> from namedtuple_table import NamedTupleTable
>>> from pathlib import Path

>>> dogs = NamedTupleTable.from_tsv(Path("dogs.tsv"))

Now you have a dict-like Mapping of data rows represented as NamedTuple objects. All data is loaded as strings, so you might need to cast back and forth to int.

>>> print(dogs)
NamedTupleTable (3 items, index = ref)

>>> for i in range(5):
...     if str(i) in dogs:
...         print(dogs[str(i)])
...
TableRow(ref='1', name='Bertie', collar='red', age='4')
TableRow(ref='2', name='Geoff', collar='blue', age='2')
TableRow(ref='4', name='Gertrude', collar='blue', age='5')

>>> dogs['4'].collar
'blue'

To use a different index column, get a new table with the .index_by method.

>>> dogs_by_name = dogs.with_index("name")
>>> dogs_by_name["Geoff"]
TableRow(ref='2', name='Geoff', collar='blue', age='2')

Release files for namedtuple-table 0.1.0.post2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for namedtuple-table 0.1.0.post2
File Size Uploaded
namedtuple_table-0.1.0.post2.tar.gz 5.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for namedtuple-table 0.1.0.post2
File Interpreter ABI Platform
namedtuple_table-0.1.0.post2-py3-none-any.whl Python 3 none any Details

Total release size: 11.3 kB

Release files / namedtuple_table-0.1.0.post2.tar.gz

Download URL namedtuple_table-0.1.0.post2.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
2fe88c380bca6e0130e070427d864c9b65efe8aea458b50db5486dd9e500b085
BLAKE2b-256 checksum
How to use checksums
2ffcbfdacefdd6e963cf0df0f7fb3f7ee791c037c63c612dcabf0d8f78e7c132
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 24, 2025.

Transparency log

Release files / namedtuple_table-0.1.0.post2-py3-none-any.whl

Download URL namedtuple_table-0.1.0.post2-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
edb578827d8feaef042e75e05b4435f75cd6f3338bafbf250bf240a6676fdf42
BLAKE2b-256 checksum
How to use checksums
56dc46e0291205c1ae30510153088e86cd7282c50dbd43e61a4186490f970a75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 24, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0.post2 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page