Skip to main content

PyTools

py_tools is a research-oriented Python toolkit for numerical economics, time series, estimation, and dataset loading utilities.

Installation

Install from PyPI:

pip install dgreenwald-py-tools

Or clone the repository and install in editable mode:

pip install -e .

Optional extras:

pip install "dgreenwald-py-tools[ml]"        # scikit-learn, patsy
pip install "dgreenwald-py-tools[datasets]"  # pandas-datareader, python-dotenv
pip install "dgreenwald-py-tools[scraping]"  # requests, beautifulsoup4, lxml
pip install "dgreenwald-py-tools[nlp]"       # nltk
pip install "dgreenwald-py-tools[mpi]"       # mpi4py
pip install "dgreenwald-py-tools[dev]"       # pytest, ruff

If you use dataset loaders, set:

export PY_TOOLS_DATA_DIR=/path/to/data

Or create a .env file in the repository root (or a parent directory):

PY_TOOLS_DATA_DIR=/path/to/data

Slurm jobs

py_tools.cluster renders typed single-job and array definitions and can submit the resulting scripts with sbatch --parsable:

from py_tools.cluster import (
    SLURM_ARRAY_TASK_ID,
    SlurmArray,
    SlurmJob,
    SlurmResources,
    submit_slurm,
    write_slurm_script,
)

job = SlurmJob(
    name="analysis",
    command=("python", "worker.py", "--index", SLURM_ARRAY_TASK_ID),
    workdir="/cluster/project",
    log_dir="/cluster/project/output/slurm",
    resources=SlurmResources(time="04:00:00", memory="16G", account="research"),
    activate="/cluster/venv/bin/activate",
    array=SlurmArray(task_count=20, max_concurrent=4),
)
script = write_slurm_script(job, "/cluster/project/output/slurm/jobs.slurm")
submission = submit_slurm(script)
print(submission.job_id)

py_tools.datasets will load .env automatically when python-dotenv is installed (included in the datasets extra).

Quick Start

from py_tools import data, time_series, state_space

# Example: call a utility function from a core module
# (see module docstrings/source for full APIs)

You can also import dataset loaders through:

from py_tools import datasets

available = datasets.list_datasets()
df = datasets.load_dataset("fred", codes=["UNRATE"])

Module Overview

Import path Contents
py_tools.time_series Kalman filter, state-space models, VAR/BVAR, HMMs
py_tools.econometrics NLS/GMM, bootstrap, local projections, high-dimensional FE
py_tools.bayesian MCMC sampling, prior distributions
py_tools.numerical Root-finding, Chebyshev approximation
py_tools.datasets Loaders for ~38 economic data sources
py_tools.data Data manipulation, aggregation, matching
py_tools.econ Discrete choice, yield curves, AIM solver
py_tools.plot Plotting utilities
py_tools.config Named model specification registry
py_tools.scraping HTML scraping and text utilities
py_tools.compute MPI array distribution

Development

pip install -e ".[dev]"
python -m pytest          # run tests
ruff check .              # lint

Contributing

  • Keep changes focused and commit one logical change at a time.
  • Follow repository coding and workflow guidelines in AGENTS.md.
  • Prefer adding deterministic tests in tests/ for new behavior.

License

MIT — see LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dgreenwald_py_tools-0.2.4.tar.gz (310.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dgreenwald_py_tools-0.2.4-py3-none-any.whl (300.2 kB view details)

Uploaded Python 3

File details

Details for the file dgreenwald_py_tools-0.2.4.tar.gz.

File metadata

  • Download URL: dgreenwald_py_tools-0.2.4.tar.gz
  • Upload date:
  • Size: 310.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for dgreenwald_py_tools-0.2.4.tar.gz
Algorithm Hash digest
SHA256 c27bb5b60befc7858ae13f51b2530ef04f163410d5262a7ff476d95906cec50d
MD5 5b8e787919bff44083e35836851ffe99
BLAKE2b-256 e2f4adecd595ed10c8fc4abad22c11943824db3bd9328cf5f7c0cfd8c3fde1b9

See more details on using hashes here.

File details

Details for the file dgreenwald_py_tools-0.2.4-py3-none-any.whl.

File metadata

File hashes

Hashes for dgreenwald_py_tools-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9cd6274f82dd3238baeafc3272aac96e4252a267bdccf38ffbfcb18aefc81157
MD5 61c0c4e3f9df34d66f6e23a156468375
BLAKE2b-256 8755e8391d8fe79ec1c67630db503560a25da9b7998d3b5a9f01037846cac5b6

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.5

2 files

This release

0.2.4 This release

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.0

2 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