This is a Python module for accessing infectious disease data.
To install this package via pip:
pip install git+https://github.com/reichlab/iddata.gitiddata loads data from these surveillance sources: NHSN hospital admissions, NSSP emergency department visits, ILINet, and FluSurv-NET. It also loads supporting population and location data.
The raw files are read at load time from the public infectious-disease-data S3 bucket, so no AWS credentials are
needed. NHSN and NSSP are snapshotted on a schedule by GitHub Actions workflows in this repository
(.github/workflows/). This lets data be loaded as it was on a given as_of date.
See docs/data-sources.md for the bucket layout, what each source reads, how versioned snapshots
and as_of work, and how the snapshot workflows run.
The steps below are for setting up a local development environment. This process entails more than just installing the package, because we need to ensure that all developers have a consistent, reproducible environment.
Developers will be using a Python virtual environment that:
- is based on the Python version specified in .python-version.
- contains the dependency versions specified in the "lockfile" (in this case requirements/requirements-dev.txt).
- contains the package installed in "editable" mode.
-
Clone this repository
-
Change to the repo's root directory:
cd iddata -
Make sure the correct version of Python is currently active, and create a Python virtual environment:
python -m venv .venv
-
Activate the virtual environment:
# MacOs/Linux source .venv/bin/activate # Windows .venv\Scripts\activate
-
Install the package dependencies and install the package in editable mode:
python -m pip install -r requirements/requirements-dev.txt && python -m pip install -e .
-
Optional: if you use
pre-commitin your workflow to automate code formatting and other tasks, install it. Otherwise, delete.pre-commit-config.yaml. -
Run the test suite to confirm that everything is working:
python -m pytest
The test suite is split into two kinds of tests:
tests/iddata/unit/— fast tests that use mocked data and make no network calls.tests/iddata/integration/— end-to-end tests that load real data from S3, CDC, SEER, and census.gov. Every test in this directory is automatically markedintegration, and the full set takes a few minutes to run.
python -m pytest # everything
python -m pytest -m "not integration" # fast, offline tests only
python -m pytest -m integration # network-dependent tests onlyBecause the package is installed in "editable" mode, you can run the code as though it were a normal Python package, while also being able to make changes and see them immediately.
Prerequisites:
Note: using pipx (instead of pip) to install uv is a handy way to ensure that uv is available for all of the Python environments on your machine.
The "lockfile" for this project is simply an annotated requirements.txt that is generated by uv (uv is a replacement for pip-compile, which could also be used). There's also a requirements-dev.txt file that contains dependencies needed for development (e.g., pytest).
While it's possible to use pip freeze to generate a detailed lockfile without a third-party tool like uv, the output of pip freeze doesn't distinguish between direct and indirect dependencies. This distinction probably doesn't matter for a small project, but on a large project, understanding the dependency graph is critical for resolving conflicts.
Additionally, uv (and pip-compile) are able to use the list of high-level dependencies in pyproject.toml to generate a detailed requirements.txt file, which is a good workflow for keeping everything in sync.
To add or remove a project dependency:
-
Add or remove the dependency in the
[dependencies]section ofpyproject.toml(or in thedevsection of[project.optional-dependencies], if it's a development dependency). Don't pin a specific version, since that will make it harder for users to install the package. -
Generate updated requirements files:
uv pip compile pyproject.toml -o requirements/requirements.txt && uv pip compile pyproject.toml --extra dev -o requirements/requirements-dev.txt -
Update project dependencies:
Note: This package was originally developed on MacOS. If you have trouble installing the dependencies.
uv pip synchas a--python-platformflag that can be used to specify the platform.# note: requirements-dev.txt contains the base requirements AND the dev requirements # # using pip python -m pip install -r requirements/requirements-dev.txt # # alternately, you can use uv to install the dependencies: it is faster and has a # a handy sync option that will cleanup unused dependencies uv pip sync requirements/requirements-dev.txt && python -m pip install -e .