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')
Metadata
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| namedtuple_table-0.1.0.post2.tar.gz | 5.6 kB | With provenance | Details for namedtuple_table-0.1.0.post2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| namedtuple_table-0.1.0.post2-py3-none-any.whl | Python 3 | none | any | Details for namedtuple_table-0.1.0.post2-py3-none-any.whl |
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 logRelease 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 logSecurity for namedtuple-table 0.1.0.post2
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for namedtuple_table-0.1.0.post2.tar.gz
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 logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.