varmeta
varmeta is a lightweight Python package for managing variable metadata in scientific, engineering, and data analysis workflows. It automatically unpacks multi-component variables and generates pandas DataFrames with rich multi-level column headers.
Purpose
Scientific and engineering data often has variables with multiple components (e.g., x, y, and z components of a force vector). varmeta makes it easy to:
- Define variables once with metadata (name, units, description, components)
- Automatically unpack component variables (e.g.,
force→force__x,force__y,force__z) - Generate pandas DataFrames with multi-index headers showing keys, names, and units
- Serialize and deserialize variable metadata to/from JSON
Quick-start tutorial
1. Define variables with metadata
import varmeta as vm
TEMP = "temp"
FORCE = "force"
# Scalar variable
temperature = vm.Var(
key=TEMP,
name="Temperature",
units="Celsius",
description="Ambient temperature",
)
# Vector variable (e.g., 3D force)
force = vm.Var(
key=FORCE,
name="Force",
units="N",
description="Force vector",
components=("x", "y", "z"),
component_axis=1,
)
2. Create a VarSet collection
# Create a VarSet from a list of Var instances
varset = vm.VarSet([temperature, force])
# Dict-like access by key
print(varset[TEMP]) # Temperature [Celsius]
print(varset[FORCE]) # Force [N]
3. Unpack and pack data with components
Component variables can be unpacked (expanded) and packed (reconstructed):
data = {TEMP: 25.0, FORCE: [10.0, 20.0, 30.0]}
# Unpack: expand components
unpacked_varset, unpacked_data = varset.unpack(data)
print(unpacked_data)
# {'temp': 25.0, 'force__x': 10.0, 'force__y': 20.0, 'force__z': 30.0}
# Pack: reconstruct original structure
packed_data = varset.pack(unpacked_data)
print(packed_data)
# {'temp': 25.0, 'force': [10.0, 20.0, 30.0]}
Component separator: Double underscore __ (e.g., force__x) minimizes collision risk with regular variable names.
Optional error handling:
unpack(data, raise_extra=True): Raise error if data contains extra keys not in VarSet (default: silently ignore)pack(data, raise_missing=True): Raise error if VarSet variables are missing from data (default: silently skip)
4. Create pandas DataFrames
It's easy to tabulate data into a DataFrame. Components are automatically unpacked, even from numpy arrays!
# Single dict → DataFrame
data = {TEMP: [30, 40], FORCE: [[200, 250, -30], [300, 350, -100]]}
df = varset.to_dataframe(data)
print(df)
# key temp force__x force__y force__z
# name Temperature Force - x Force - y Force - z
# units Celsius N N N
# 0 30 200 250 -30
# 1 40 300 350 -100
5. Create DataFrames from records
You can also pass a list of data dictionaries (records):
records = [
{TEMP: 30, FORCE: [200, 250, -30]},
{TEMP: 40, FORCE: [300, 350, -100]},
]
df = varset.to_dataframe(records)
print(df)
# key temp force__x force__y force__z
# name Temperature Force - x Force - y Force - z
# units Celsius N N N
# 0 30 200 250 -30
# 1 40 300 350 -100
Serialization
You can serialize VarSet metadata to JSON and reconstruct it later:
import json
# Serialize to JSON-compatible dict
var_data = varset.to_dict()
json_str = json.dumps(var_data)
# Deserialize from dict
varset_recreated = vm.VarSet.from_dict(json.loads(json_str))
# Verify equality
for key in varset:
print(f"{key}: {'matches!' if varset[key] == varset_recreated[key] else 'differs!'}")
# Output:
# temp: matches!
# force: matches!
Describing table columns
Tables written by other tools often use their own flat column names, such
as force_x or loads_force_x. VarSet.match_column finds the Var a
column refers to, so you can look up its units and description.
Combine VarSets with | to add your own Vars to a library's set.
extra = vm.Var(key="speed", name="Speed", units="m/s", description="Speed")
combined = varset | vm.VarSet([extra])
naming = vm.ColumnNaming(
separator="_", # between key and component
prefixes=("loads_",), # group prefixes to strip
derived=("mag",), # extra suffixes for any vector Var
)
for column in ["temp", "loads_force_x", "force_mag", "speed", "other"]:
match = combined.match_column(column, naming)
if match is None:
print(f"{column}: no match")
else:
print(f"{column}: {match.var.key} {match.component} "
f"[{match.var.units}]")
# temp: temp None [Celsius]
# loads_force_x: force x [N]
# force_mag: force mag [N]
# speed: speed None [m/s]
# other: no match
match_column returns a ColumnMatch(column, var, component, stem) with
the parent Var, or None for an unknown column. The whole column name is
tried first, then the column split at its last separator. Without a
naming argument it uses varmeta's own {key}__{component} convention,
so it matches every column key made by to_dataframe and unpack.
Merging raises ValueError if both VarSets define the same key
differently.
Metadata
Release files for varmeta 0.3.0
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 |
|---|---|---|---|---|
| varmeta-0.3.0.tar.gz | 39.7 kB | Without provenance | Details for varmeta-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| varmeta-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for varmeta-0.3.0-py3-none-any.whl |
Total release size: 53.4 kB
Release files / varmeta-0.3.0.tar.gz
| Download URL | varmeta-0.3.0.tar.gz |
|---|---|
| Size | 39.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e4036967a63234a273b04796f71ee3dc0db77ef2b9b01a0d4c17c74e896cb578
|
|
BLAKE2b-256 checksum How to use checksums |
f4895908d441cb90708988600ef2b2e09c1860a9e73d97d70b3ea804ec326cf4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.24 {"installer":{"name":"uv","version":"0.12.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / varmeta-0.3.0-py3-none-any.whl
| Download URL | varmeta-0.3.0-py3-none-any.whl |
|---|---|
| Size | 13.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
440ff6ab13df599ffebe6f640b4fd517bd071434a04f1d7a80370f4fbfdc83f9
|
|
BLAKE2b-256 checksum How to use checksums |
aa9734a47f0b4755a4f50bf36371c56c9657d930f2e4a8d71a5e1529935f1949
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.24 {"installer":{"name":"uv","version":"0.12.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for varmeta 0.3.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.