Skip to main content

DataTrade Processing

[!IMPORTANT] Project development has moved to Codeberg.

Overview

DataTrade Processing is a robust, high-performance Python library designed for processing and analyzing international trade data for Puerto Rico. Built on top of Polars, the project employs a configuration-driven design to handle dynamic aggregation, unit conversions, and advanced rolling statistical analysis across various taxonomy levels and time frames.


Key Features

  • High-Performance Processing: Leverages Polars DataFrames for fast, memory-efficient data manipulation and aggregation.

  • Flexible Data Sources: Supports ingestion from both organizational (org) and JP-specific (jp) trade data sources.

  • Multi-Level Classification: Aggregate metrics by:

    • Total trade (total)
    • Harmonized Tariff Schedule code (hts)
    • North American Industry Classification System code (naics)
    • Country (country)
  • Flexible Time Frames: Group trade data by calendar year, fiscal year (beginning in July), quarter, or month.

  • Granular Filtering: Filter data dynamically by date ranges, specific calendar years, agricultural indicators (agri_prod), and taxonomy code prefixes.

  • Standardized Unit Conversions: Automatically normalizes diverse source units (kilograms, liters, metric tons, dozens, cubic meters, grams, etc.) into a unified metric representation.

  • Advanced Price Analysis (process_price):

    • Computes HS4-level import and export unit prices.
    • Calculates 3-month rolling averages and standard deviations.
    • Derives statistical price bands ($\pm 2\sigma$) and monthly market rankings.
    • Evaluates year-over-year percentage changes and ranking shifts.

Requirements

  • Python: 3.10 or higher
  • Core Dependencies: polars
  • Development/Testing Dependencies: pytest
  • External Dependencies: pr-imports

Installation

Clone the repository and set up your environment using your preferred package or environment manager:

git clone https://codeberg.org/gitinference/jp-imports.git
cd jp-imports

# Using devenv (recommended if configured)
devenv shell --profile dev

# Or via standard pip requirements
pip install -r requirements.txt

Usage

Initializing JPTrade

The core processing logic is encapsulated within the JPTrade class. By default, processed outputs are written to a local data/ directory and logs are recorded in data.log.

from jp_imports.jp_imports import JPTrade

# Initialize with default settings

trade = JPTrade()

# Or specify custom directories and logs

trade = JPTrade(saving_dir="data/", log_file="data.log")

Processing International Trade Data

Use the process_int_jp() method to load, filter, convert, and aggregate trade datasets.

result = trade.process_int_jp(
    level="total",
    time_frame="yearly",
)

Supported Parameters

Parameter Type Description
level str Aggregation level: "total", "hts", "naics", or "country".
time_frame str Time period: "yearly", "fiscal", "qtr", or "monthly".
datetime str Optional filter for a single year ("2024") or range ("2024-01-01+2024-12-31").
agriculture_filter bool If True, restricts records to agricultural products (agri_prod == 1).
source str Data source origin: "org" (default) or "jp".
level_filter str Optional taxonomy prefix filter (e.g., level_filter="2207" for HTS codes).

Price Analysis Pipeline

To generate rolling price metrics, unit costs, bands, and year-over-year variations at the HS4 classification level over a 3 month window, use process_price():

# Standard price processing

prices = trade.process_price()

# Isolated for agricultural commodities

ag_prices = trade.process_price(agriculture_filter=True)

Running Tests

Execute the test suite using pytest:

pytest

Project Architecture

jp-imports/
├── src/
│   └── jp_imports/
│       ├── jp_imports.py
│       └── resources/
│           └── code_agr.json
├── tests/
├── requirements.txt
├── environment.yml
├── README.md
└── LICENSE

License

Distributed under the GPL v3 License. See LICENSE for more information.

Download files

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

Source Distribution

jp_imports-1.7.2.tar.gz (235.0 kB view details)

Uploaded Source

Built Distribution

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

jp_imports-1.7.2-py3-none-any.whl (22.4 kB view details)

Uploaded Python 3

File details

Details for the file jp_imports-1.7.2.tar.gz.

File metadata

  • Download URL: jp_imports-1.7.2.tar.gz
  • Upload date:
  • Size: 235.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for jp_imports-1.7.2.tar.gz
Algorithm Hash digest
SHA256 a6d16f987f8934a2fffbda33babcc883b348c0c6d1c30f60903a029a677678c6
MD5 1c1d1704d8bd7c74d332c84c7d606d4f
BLAKE2b-256 f96f6ea80fc2b5d76c7b6db0cc8930c3493cd1b78f1acd019cfe364631d13679

See more details on using hashes here.

File details

Details for the file jp_imports-1.7.2-py3-none-any.whl.

File metadata

  • Download URL: jp_imports-1.7.2-py3-none-any.whl
  • Upload date:
  • Size: 22.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for jp_imports-1.7.2-py3-none-any.whl
Algorithm Hash digest
SHA256 37ce406b3328401cdec131a3019b61c61061cd485f9660b60191f35c3761b9da
MD5 8910dcbcf342ad9b3738cd0eacf92207
BLAKE2b-256 4c7d88035ff7d9130d9df1c0c738dabb9410ea98d04e8ffb28f2822417b01127

See more details on using hashes here.

Release history Release notifications | RSS feed

1.8.0

2 files

1.7.5

2 files

1.7.4

2 files

This release

1.7.2 This release

2 files

1.7.1

2 files

1.7.0

2 files

1.6.7

2 files

1.6.6

2 files

1.6.5

2 files

1.6.4

2 files

1.6.3

2 files

1.6.2

2 files

1.6.1

2 files

1.6.0

2 files

1.5.1

2 files

1.5.0

2 files

1.4.1

2 files

1.3.0

2 files

1.2.0

2 files

1.1.0

2 files

1.0.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