Skip to main content

econcomplex

version python license tests

econcomplex is a Python library for economic complexity and regional science indicators. It consolidates, in a single coherent API, the tools scattered across the reference packages of the field — EconGeo (R), economiccomplexity (R), py-ecomplexity, py-economic-complexity — and adds a target-oriented optimization layer (ECI Optimization and strategic diffusion) that, to our knowledge, is not available in any other package.

Leia em português: README.pt-BR.md.


What it computes

Group Indicators
Complexity ECI / PCI through a single entry point — eci_pci(mat, method="eigenvector" | "reflections" | "fitness") — plus subnational ECI projected with an external PCI
Relatedness / Product Space Proximity (discrete, correlation, cosine), relatedness density, distance, relative relatedness (option-set z-score), co-occurrence indices, cross-space proximity between two activity spaces
Specialization Location quotient, Hachman, Krugman, Hoover specialization coefficient, export similarity
Inequality / Concentration Gini, locational Gini, Hoover-Gini, Hoover index, Herfindahl-Hirschman, Shannon entropy
Productivity PRODY, EXPY, Product Gini Index, Product Emissions Intensity Index
Patents Ease of recombination, modular complexity
Dynamics Growth rates, entry/exit tracking — matrix-pair and long-panel APIs
Outlook Complexity Outlook Index (COI) and Gain (COG)
ECI Optimization Stepping-stone forecast model, entry-effort matrix, exact 0–1 program for minimal-effort diversification portfolios, growth targeting (Stojkoski & Hidalgo 2026)
Strategic diffusion Complex-contagion calibration, five diversification strategies, optimal entry sequencing (Alshamsi, Pinheiro & Hidalgo 2018)

90 public functions in total — the PDF documentation carries a complete API reference and an interpretation guide for every indicator family.

Installation

pip install econcomplex

Or, for the latest development version straight from GitHub:

pip install git+https://github.com/eltonfreitas/econcomplex.git

Requires Python ≥ 3.10 with numpy ≥ 1.21 (1.x and 2.x supported), pandas ≥ 1.3, scipy ≥ 1.9. For local development:

git clone https://github.com/eltonfreitas/econcomplex.git
cd econcomplex
pip install -e .[dev]
pytest          # tests + docstring examples

Quick start

1. One call, every indicator (long-format data)

import pandas as pd
import econcomplex as ec

df = pd.read_csv("my_data.csv")        # columns: region, sector, employment[, year]

result = ec.compute_complexity(
    df,
    cols={"loc": "region", "act": "sector", "val": "employment", "time": "year"},
    method="eigenvector",              # or "reflections" / "fitness"
)
# adds columns: rca, mcp, diversity, ubiquity, eci, pci, density, distance, coi, cog
# with a "time" column the pipeline recomputes everything per period automatically

2. Working with matrices

mat = ec.pivot_to_matrix(df, "region", "sector", "employment")

eci, pci   = ec.eci_pci(mat)                      # eigenvector method (default)
eci2, pci2 = ec.eci_pci(mat, method="fitness")    # same call, other method

phi     = ec.product_proximity(mat)               # product space
density = ec.density(mat, phi=phi)                # 0–100 % relatedness density
coi     = ec.coi(mat, pci, phi=phi)               # diversification potential

Degenerate units (zero diversity or ubiquity) are trimmed automatically and returned as NaN; for very sparse data (e.g. municipal trade) use the well-connected core: ec.eci_pci(mat, dmin=2, umin=2) or ec.trim_core(mat, 2, 2).

3. Diversification targets (ECI Optimization)

Requires a panel with at least the periods t, t+τ and t+Δt:

model = ec.calibrate_steppingstone(panel, "region", "sector", "employment",
                                   "year", horizon=10, steppingstone=5)

portfolio = ec.eci_optimization(mat, model, delta_eci=0.1)
# → minimal-effort set of new activities per region that raises its ECI by 0.1

# Growth targeting: convert a 3.5 %/yr target into an ECI target
gm       = ec.calibrate_growth_model(macro, "region", "year", "gdppc", "eci")
eci_star = ec.eci_target_for_growth(gm, 0.035, gdppc_now)
portfolio = ec.eci_optimization(mat, model, target_eci=eci_star)

# When to make unrelated bets (strategic diffusion)
adj  = ec.proximity_network(mat)
fit  = ec.calibrate_contagion(panel, "region", "sector", "employment", "year",
                              adjacency=adj)
best = ec.optimize_sequence(adj, ec.mcp(mat).loc["my_region"],
                            B=fit["B"], alpha=fit["alpha"])

Data format

The high-level API expects long-format (tidy) data — one row per (location, activity[, period]):

region sector employment year
SP cnae_10 12345 2022
SP cnae_25 6789 2022
RJ cnae_10 9012 2022

Requirements: no duplicate (location, activity, period) rows, non-negative values, no NaN, a single geographic level and a single activity classification per analysis. Works with employment, exports, patents, payroll — anything shaped location × activity × value. To experiment without data: df = ec.make_sample_data(n_locs=50, n_acts=30, seed=42).

Documentation and examples

  • Technical documentation (PDF) — formulas, step-by-step usage, interpretation guide, and the complete API reference: English · Português (LaTeX sources in docs/)
  • Runnable examples: examples/basic_usage.py (guided tour of every indicator group) and examples/eci_optimization.py (optimization layer end to end)
  • In-code reference: every function has a full NumPy-style docstring — help(ec.eci_pci)
  • CHANGELOG.md — release history

The API has three layers (detailed map in the PDF): entry points such as eci_pci and compute_complexity; advanced implementations they delegate to (method_of_reflections, fitness_complexity, …); and short aliases bound to the same objects (density, hhi, coi, pgi, …).

Validation

The test suite includes exact validations against the literature: the eigenvector ECI/PCI uses the proper non-symmetric solver; the strategic diffusion module reproduces the closed-form solution of Alshamsi et al. (2018, eq. 2) on the wheel network; relative relatedness follows Pinheiro et al. (2022, eq. 7) exactly; and the 0–1 portfolio program is solved exactly with scipy.optimize.milp. On the 2022–2024 BACI trade data the library recovers the canonical ECI country ranking.

Citation

@software{freitas_econcomplex_2026,
  author  = {Freitas, Elton},
  title   = {econcomplex: economic complexity and regional science indicators in Python},
  year    = {2026},
  version = {1.1.0},
  url     = {https://github.com/eltonfreitas/econcomplex}
}

Please also cite the original papers of the indicators you use — full list in the PDF documentation. Key references: Hidalgo & Hausmann (2009, PNAS); Hidalgo et al. (2007, Science); Tacchella et al. (2012, Sci. Rep.); Alshamsi, Pinheiro & Hidalgo (2018, Nat. Commun.); Pinheiro et al. (2022, Res. Policy); Stojkoski & Hidalgo (2026, Res. Policy).

License

MIT — see LICENSE.

Metadata

Release files for econcomplex 1.1.0

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

Source distribution (sdist)

Source distribution for econcomplex 1.1.0
File Size Uploaded Provenance Actions
econcomplex-1.1.0.tar.gz 1.1 MB Without provenance Details for econcomplex-1.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 1.1 MB

Release files / econcomplex-1.1.0.tar.gz

Download URL econcomplex-1.1.0.tar.gz
Size 1.1 MB
Tags Source
SHA-256 checksum
How to use checksums
707930d94ffc7b71d69029d1eb46a1b78a9d949b53181e8580bce5d56dd5dcdf
BLAKE2b-256 checksum
How to use checksums
d0af605dbf07a7a54bb82db0dfe823ea0c8f01cb1bfce680063d96025a3f61e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / econcomplex-1.1.0-py3-none-any.whl

Download URL econcomplex-1.1.0-py3-none-any.whl
Size 67.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
26e264e32b0039b3a8689dd36e7d30a9c8b5e4d53dfb3af6741e2383c81c7f6e
BLAKE2b-256 checksum
How to use checksums
5c2e2879c27e34799c5b50238bfa559e067b8098a71f20cf97c16ed03a072dbb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Security for econcomplex 1.1.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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