Skip to main content

demetrapy

PyPI Python CI

demetrapy exposes JDemetra+ X13 and TRAMO/SEATS through Python, pandas, a command-line interface, and a Streamlit dashboard. It supports monthly through yearly data, calendars, regressors, outliers, ARIMA models, and forecasts.

Installation

demetrapy requires Python 3.11 or later and Java 8 or later.

python -m pip install demetrapy
demetrapy check

New users can follow the five-minute quickstart from installation through validation and the first adjustment.

For development from a clone:

python -m venv .venv
source .venv/bin/activate
python -m pip install -e .

The first calculation downloads the pinned demetra-tstoolkit 2.2.6 JAR from Maven Central and stores it in ~/.cache/demetrapy. Set DEMETRAPY_JAR to the path of a local copy when automatic download is not suitable. The Windows guide covers Command Prompt and offline setup.

Python interface

For a pandas object with a regular DatetimeIndex, adjust_dataframe() infers the observation frequency and adjusts each column separately:

import pandas as pd

from demetrapy import adjust_dataframe

data = pd.DataFrame(
	{"production": observations},
	index=pd.date_range("2015-01-01", periods=len(observations), freq="MS"),
)

result = adjust_dataframe(data, method="x13", spec="RSA4")
adjusted = result.seasonally_adjusted["production"]

The lower-level adjust() function accepts one regular sequence and an explicit starting period:

from demetrapy import adjust

result = adjust(
    values,
    frequency="Quarterly",
    start_year=2005,
    start_period=1,
    method="tramoseats",
    spec="RSA4",
)
adjusted = result.seasonally_adjusted.values

For quarterly data, adjust_dataframe() and adjust_csv() infer frequency from regular dates. Raw sequences have no dates, so pass frequency="Quarterly" and a one-based start_period. See the quarterly example.

Both functions always return a stable result object. Their components attribute exposes six named series used in routine work:

Attribute Compact alias Series
observed y observed series
calendar_adjusted ycal calendar-adjusted series
seasonally_adjusted sa seasonally adjusted series
trend t trend-cycle
seasonal s seasonal component
irregular i irregular component

Use to_compact_dict() or to_compact_frame() when the short aliases are needed. Forecasts preserve their own future domain under result.forecasts; to_forecast_dict() provides y_f, ycal_f, sa_f, t_f, s_f, and i_f when a forecast horizon is active:

seasonal_forecast = result.forecasts.seasonal
forecast_values = result.to_forecast_dict()

Pandas results also provide to_forecast_frame() and to_combined_frame(). For example, result.to_combined_frame(compact=True)[("sales", "sa")] returns one seasonally adjusted series spanning history and forecast dates.

Choose a configuration style

These interfaces run the same engine. Choose one style per call:

Style Best for
Method-specific object reusable, discoverable Python configuration
Direct keywords short one-off Python calls
JSON file CLI workflows and reviewed configuration files

Method-specific objects prevent X11 and SEATS settings from being mixed:

from demetrapy import TramoSeatsConfig, X13Config, adjust_dataframe

x13 = X13Config(spec="RSA4", forecast_horizon=12)
tramoseats = TramoSeatsConfig(
  spec="RSAfull",
  seats={"prediction_length": 12},
)

x13_result = adjust_dataframe(data, config=x13)
tramoseats_result = adjust_dataframe(data, config=tramoseats)

The equivalent direct-keyword call is:

x13_result = adjust_dataframe(
  data,
  method="x13",
  spec="RSA4",
  forecast_horizon=12,
)

The same settings can instead live in JSON for adjust_csv() or the CLI. Existing code does not need to migrate.

Set detailed=True to additionally populate the full JDemetra+ result dictionary, diagnostics, processing messages, backcasts, and fitted ARIMA model:

detailed = adjust(
    values,
    frequency="Monthly",
    start_year=2015,
    forecast_horizon=12,
    detailed=True,
)

print(detailed.arima_model.notation)
forecast = detailed.series["final.sa_f"]

Command line

The command-line interface reads a regular CSV file with date and value columns:

date,value
2019-01-01,101.2
2019-02-01,103.8

The default calculation is monthly X13 with the RSA4 preset:

demetrapy input.csv --output adjusted.csv

A JSON file records a fuller specification:

demetrapy \
  --data input.csv \
	--config examples/configs/tramoseats_full.json \
  --output adjusted.csv

The output contains y, ycal, sa, t, s, and i. See the usage guide for all options.

Validate a configuration without starting Java, or create a starter template:

demetrapy validate config.json --data input.csv
demetrapy init-config --method tramoseats --output config.json

Python callers can process the same files directly:

from demetrapy import adjust_csv

result = adjust_csv("input.csv", config="config.json", output="adjusted.csv")

For reproducible operational runs, opt in to a JSON audit manifest and append-only history without storing observation values:

result = adjust_csv("input.csv", output="adjusted.csv", audit="audit/")

Specifications and regressors

The package constructs an isolated JDemetra+ processing context for each calculation. Preset defaults remain those of JDemetra+ unless an option is overridden explicitly.

Area Available controls
Methods X13 and TRAMO/SEATS presets
RegARIMA transformation, explicit ARIMA, automatic model selection, estimation controls
Calendar built-in trading days, working days, leap year, Easter, and UserDefined variables
Regression user variables, fixed coefficients, interventions, and ramps
Outliers prespecified and automatic detection
Decomposition X11 filters and limits; SEATS approximation and boundary controls
Output forecasts, backcasts, benchmarking, diagnostics, and processing messages

UserDefined calendar variables use a separate pool; each target selects the columns used by its equation.

See the configuration reference for supported values.

Inspection

A static summary plot can be produced from the command line:

demetrapy --data input.csv --plot-output adjustment.png

The local dashboard is included in the standard installation:

demetrapy-dashboard

It accepts CSV and JSON files, includes built-in sample datasets, and provides interactive results, diagnostics, model details, and downloads.

Examples

See the example guide, or run every example:

python examples/run_all.py

Reproducibility and compatibility

See compatibility for supported Python, Java, and JDemetra+ versions. CI tests both engines on Linux, Windows, and macOS.

python -m unittest discover -s tests

demetrapy is an independent interface to JDemetra+ and is not an official publication of the JDemetra+ project.

Download files

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

Source Distribution

demetrapy-0.3.2.tar.gz (64.5 kB view details)

Uploaded Source

Built Distribution

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

demetrapy-0.3.2-py3-none-any.whl (53.4 kB view details)

Uploaded Python 3

File details

Details for the file demetrapy-0.3.2.tar.gz.

File metadata

  • Download URL: demetrapy-0.3.2.tar.gz
  • Upload date:
  • Size: 64.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.15

File hashes

Hashes for demetrapy-0.3.2.tar.gz
Algorithm Hash digest
SHA256 9f3080c8466391a674b147344a884e5f599c291a005e450116360b7e8275fd81
MD5 77733d18313dadffd9fc97c4dab97aba
BLAKE2b-256 5426537280a9c70f3cb047a65477057ad4fae9c81b64c6f697405af394a8ed05

See more details on using hashes here.

File details

Details for the file demetrapy-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: demetrapy-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 53.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.15

File hashes

Hashes for demetrapy-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a3b739e9b2c52057e3a845abec5cc6fc61ada0cc102e31daea3b0ed7a39398d7
MD5 903cc0f9335fa521d424fefe5084243b
BLAKE2b-256 32d50a982152aab70bca39c279b69fbec1ed400ecaa2e3b77f24dd4a98beda7e

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.3.2 This release

2 files

0.3.1

2 files

0.3.0

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

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