Skip to main content

pynhts

ci status python license

Typed, survey-weight-aware Python access to US National Household Travel Survey (NHTS) microdata.

Scope and status (0.1.0, alpha). Only the 2017 wave is supported; other waves come after this one is solid. The API may still change. Results are validated against FHWA's published tables: 20 of 24 figures reproduce completely and 4 gaps are reported openly in docs/validation.md.

Install

pip install pynhts
pynhts fetch --replicates        # download, verify (SHA-256) and convert; about 0.4 GB of Parquet, plus 1.8 GB of raw CSV that you may delete afterwards

Already have the NHTS 2017 CSV files? pynhts register <folder> adopts them after checking their hashes.

What it does

import pynhts
data = pynhts.load(2017)

# lazy, validated tables: columns are joined from the table that owns them
trips = data.trips(["TRPMILES", "TRPTRANS", "HHFAMINC", "R_AGE"])

# weighted statistics with jackknife (JKn) standard errors and 95 % margins of error
s = data.survey("person", ["R_AGE_IMP", "DRIVER"])
s.total(domain=s.rows["DRIVER"] == "01")        # 223,277 thousand drivers, MOE 827 thousand
data.survey("trip", ["TRPMILES"]).mean("TRPMILES")   # 10.70 miles, MOE 0.40

# replicate a published table and see every gap
from pynhts import recipes
print(recipes.to_markdown(recipes.run("stt2017", data)))

# machine-learning bridge
from pynhts import ml
arr = ml.to_arrays(trips, ["TRPMILES", "R_AGE"], target="TRPTRANS", weight="WTTRDFIN")
Module Purpose
pynhts.io verified download, offline mode, deterministic Parquet cache
pynhts.core codebook-derived schema, NHTSData loader, missing-code handling
pynhts.stats JKn totals, means, proportions, ratios; margins of error
pynhts.recipes replication of published tables with honest status per figure
pynhts.ml NumPy / PyTorch / graph export (PyTorch optional)

Why a library

Correct NHTS analysis has many silent traps (a data server that returns HTTP 200 for missing files, string codes with leading zeros, -1 skips that are not missing data, 107 copied parent columns in the child tables, a vehicle PERSONID that is not the person key, ...). They are documented in docs/data_notes.md and each is covered by a test.

Validation

  • All 3,807 coded values of the official codebook (counts and weighted totals) reproduce.
  • 24 figures from Tables 1 and 3 of FHWA's Summary of Travel Trends: 2017 NHTS, with margins of error: 20 reproduce completely, 2 reproduce the estimate but not the margin of error, 2 do not reproduce. See docs/validation.md.

Documentation

Methods · Data notes · Validation · Roadmap · Contributing · Changelog

Data

The NHTS microdata are public data of the US Federal Highway Administration (https://nhts.ornl.gov). They are never bundled with or committed to this repository.

Development

uv venv && uv pip install -e ".[dev]"
pytest                             # unit tests, no data needed
pytest -m data                     # real-data tests (files registered in the pynhts cache)
pytest -m network -o addopts=-ra   # live ORNL download, manual only

Citation

See CITATION.cff. License: BSD-3-Clause.

Metadata

Release files for pynhts 0.1.1

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

Source distribution (sdist)

Source distribution for pynhts 0.1.1
File Size Uploaded Provenance
pynhts-0.1.1.tar.gz 149.0 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pynhts 0.1.1
File Interpreter ABI Platform
pynhts-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 283.0 kB

Release files / pynhts-0.1.1.tar.gz

Download URL pynhts-0.1.1.tar.gz
Size 149.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b88f1281b5b11983779fa37004ebfcd663c0bf6b8f39cfab33fb9115b2d0fe47
BLAKE2b-256 checksum
How to use checksums
ed56c641db7b2e83861a7023931e39ea5f8ee3fd3cff36555c658d7b9cc73645
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 17, 2026.

Transparency log

Release files / pynhts-0.1.1-py3-none-any.whl

Download URL pynhts-0.1.1-py3-none-any.whl
Size 134.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ad5924e01d0b64502058a9a12d0f024ebadd7a20440f8174ac4823a69a1f3a76
BLAKE2b-256 checksum
How to use checksums
3d35d9cbdfa1b4160f9db6f64e04370a4243924f392ec5606878f46ec74c434f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 17, 2026.

Transparency log

Security for pynhts 0.1.1

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

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pynhts-0.1.1.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 Oct 17, 2026.

Transparency log

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.

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