Skip to main content
EcoTrace Logo

EcoTrace

High-Precision Energy and Emissions Instrumentation


v1.7.1 — Performance & Telemetry Stability Patch. High-performance in-memory CPU database caching, defensive isolation in LangChain tracking callbacks, narrow terminal ASCII scaling fixes, and container environment safeguards.

EcoTrace is a lightweight library for granular carbon footprint measurement of Python applications. No configuration files, no background services—just real-time hardware-level transparency.

Real-time monitoring | 200+ Global Zones | AI-powered insights | Zero-configuration


PyPI - Version Python 3.8+ Downloads License: MIT DOI OpenSSF Scorecard OpenSSF Best Practices codecov Join Discord



EcoTrace Demo

Function-level carbon measurement with real-time monitoring


Core Features in v1.7.0

Latest Release. v1.7.0 introduces native LangChain callback instrumentation, global carbon grid database expansion to 200+ countries, terminal ASCII table reporting, and streamlined CPU architecture resolution.

  • Native LangChain Callback (ecotrace.callbacks.langchain) — Thread-safe EcoTraceLangChainCallback for LangChain and chat models. Measures process-scoped energy and carbon consumption per run_id, recording model names, execution durations, emissions ($gCO_2$), and provider token usage.
  • Global Grid Expansion (200+ Countries/Zones) — Built-in CARBON_INTENSITY_MAP upgraded with verified country-level generation intensity data from the Ember Climate 2025/2026 dataset, providing offline local grid resolution across 209 countries and territories with zero configuration.
  • Terminal ASCII Analysis Table (ecotrace analyze --table) — Bordered per-function breakdown table with responsive terminal width auto-scaling, column totals, and zero new third-party dependencies.
  • Unified Hardware Specification Resolution — Direct matching against the 6,980+ CPU specification dataset for all x86 and Apple Silicon architectures, eliminating deprecated hardcoded mappings.
  • HuggingFace & CodeCarbon Drop-in Interoperability — Full compatibility with HuggingFace TrainerCallback and CodeCarbon API signatures (EmissionsTracker, @track_emissions).

Quick Install

pip install ecotrace

Optional extras:

pip install ecotrace[gpu]   # NVIDIA GPU support
pip install ecotrace[ai]    # Gemini AI insights
pip install ecotrace[all]   # Everything

Quick Start

Option 1: Zero-Code Profiling (CLI + Cloud Sync)

Authenticate your terminal once, then profile any script without changing source code:

# 1. Login with your ingestion key from https://ecotracelibrary.com
ecotrace login --key eco_usr_abc123...

# 2. Run your script — metrics automatically stream to your web dashboard!
ecotrace run my_script.py

Option 2: Programmatic Tracking & Cloud Dashboard

Decorate functions for granular instrumentation and stream metrics to your web account:

from ecotrace import EcoTrace

# Connects directly to your hosted account at https://ecotracelibrary.com
eco = EcoTrace(api_key="eco_usr_abc123...", region_code="US")

@eco.track
def my_function():
    # Your heavy processing here
    pass

my_function()

# Export audit-ready reports or check cumulative totals
eco.generate_pdf_report("carbon_audit.pdf")
print(f"Total Carbon Emitted: {eco.total_carbon} gCO2")

Option 3: Carbon Budget Mode

Set a limit and let EcoTrace enforce it:

eco = EcoTrace(
    region_code="TR",
    carbon_limit=5.0,                   # 5 gCO2 budget
    on_budget_exceeded=lambda t, l: print(f"Budget exceeded: {t:.4f}/{l:.4f} gCO2")
)

@eco.track
def training_pipeline():
    ...

training_pipeline()
print(f"Remaining budget: {eco.remaining_budget} gCO2")

Option 4: HuggingFace Transformers Integration

Log step-by-step carbon emissions automatically inside HuggingFace Trainer:

from transformers import Trainer
from ecotrace.callbacks import EcoTraceHuggingFaceCallback

trainer = Trainer(
    model=model,
    args=training_args,
    callbacks=[EcoTraceHuggingFaceCallback()],
)
trainer.train()

Option 5: LangChain Integration

Measure the carbon footprint of every LLM call, chain, or agent run. Concurrent calls (batch(), async agents) are tracked separately by run_id:

from ecotrace.callbacks import EcoTraceLangChainCallback

cb = EcoTraceLangChainCallback(project_name="rag-pipeline")
llm.invoke("Summarise this document...", config={"callbacks": [cb]})

print(cb.total_emissions_g)  # gCO2 across all LLM calls
print(cb.records)            # per-call breakdown (model, duration, emissions, token usage)

Option 6: Drop-in CodeCarbon Compatibility

Migrate legacy codebases with zero refactoring — just change your import:

# from codecarbon import EmissionsTracker  <-- Change to EcoTrace:
from ecotrace import EmissionsTracker

tracker = EmissionsTracker(project_name="bert-finetuning")
tracker.start()
# ... your model training or inference ...
emissions = tracker.stop()
print(f"Emissions: {emissions:.6f} kg CO2")

Expected Output

When initialized, EcoTrace performs automated hardware detection:

[EcoTrace] INFO: [INFO] EcoTrace instrumentation session initialized (STATIC).
[EcoTrace] INFO: -----------------------------------------------------
[EcoTrace] INFO: Region        : TR (475 gCO2/kWh)
[EcoTrace] INFO: Hardware Logic: 13th Gen Intel Core i7-13700H
[EcoTrace] INFO: Specifications: 20 Cores | 45.0W TDP
[EcoTrace] INFO: Energy Sensor : Boavizta Advanced Estimation
[EcoTrace] INFO: Memory Config : 15.6 GB DDR4
[EcoTrace] INFO: GPU Accelerator: Intel Iris Xe Graphics (15.0W TDP)
[EcoTrace] INFO: -----------------------------------------------------

At process exit, a session summary is printed automatically:

=======================================================
  EcoTrace — Session Summary
=======================================================
  Duration       : 12.34s
  Functions      : 5 tracked
  Total Carbon   : 0.00312000 gCO2
  Region         : TR (475 gCO2/kWh)
  Budget         : 0.003120 / 5.000000 gCO2 (0.1%) [OK]
  Equivalent     : 0.4 min of LED bulb (10W)
=======================================================

CI/CD & Testing Integration

Official GitHub Action (Carbon Gate)

Enforce carbon emission budgets directly in your GitHub pull requests. Add this to your .github/workflows/ci.yml:

- name: Run Tests with Carbon Profiling
  run: pytest --ecotrace

- name: EcoTrace Carbon Gate
  uses: Zwony/ecotrace@v1.7.0
  with:
    budget: '5.0'    # Fails pipeline if total test emissions exceed 5.0 gCO2
    region: 'US'

Pytest Plugin Integration

Measure per-test function carbon footprints directly from your test suite:

pytest --ecotrace

Manual CLI Gate

Run the gate locally or inside custom continuous integration pipelines:

ecotrace gate --budget 5.0 --region US

If total emissions recorded in ecotrace_log.csv exceed the budget, the command exits with code 1 — preventing carbon-heavy regressions from merging into production.


Why EcoTrace?

Feature EcoTrace v1.6 CodeCarbon CarbonTracker
Sampling Interval 50ms 15s Per Epoch
Isolation Process-scoped System-wide System-wide
Cloud Dashboard Sync Native No No
Multi-GPU Tracking Continuous (Aggregated) Single GPU Per Epoch
CPU Dataset 6,980+ CPUs Limited Limited
Budget Enforcement Built-in No No
CI/CD Gate Built-in No No
Idle Noise Subtraction Automatic No No
Async Support Native Limited No
  • Deep Transparency: Derived from 6,980+ verified manufacturer TDP specifications rather than category averages.
  • Fail-Safe Architecture: Guaranteed application continuity even if hardware drivers or API keys are missing.
  • Actionable AI: Integrates with Google Gemini to provide specific code optimization advice (optional).

Academic Benchmarks & Empirical Research

EcoTrace includes a reproducible Academic Benchmark Suite designed for peer-reviewed green computing research. Every article in benchmarks/articles/ is auto-generated from real measurement JSONs in benchmarks/results/ by benchmarks/report_generator.py — re-run the generator after new measurements to keep the published numbers in sync.

Citing EcoTrace

If you use EcoTrace or its benchmark suite in scientific publications:

@software{ozkal2026ecotrace,
  author = {Ozkal, Emre},
  title = {EcoTrace: High-Precision Energy and Emissions Instrumentation for Python},
  year = {2026},
  url = {https://github.com/Zwony/ecotrace},
  version = {1.6.0}
}

Documentation

Full documentation is available at ecotracelibrary.com and ecotrace.readthedocs.io.


Citation

If you use EcoTrace in academic research or sustainability audits, please cite:

@software{ecotrace2026,
  author = {Ozkal, Emre},
  title = {EcoTrace: High-Precision Energy and Emissions Instrumentation for Python},
  year = {2026},
  publisher = {Zenodo},
  version = {v1.7.1},
  doi = {10.5281/zenodo.22834060},
  url = {https://doi.org/10.5281/zenodo.22834060}
}

Contributing

We welcome contributions! Please see our CONTRIBUTING.MD for guidelines on reporting bugs, suggesting features, or contributing hardware data.


Community

Join Discord

CHANGELOG.md · SECURITY.MD


Author and License

Emre Ozkal — GitHub · ecotraceteam@gmail.com

MIT License — Use it however you like.

Developed for sustainable software development practices.

Metadata

Release files for ecotrace 1.7.1

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

Source distribution (sdist)

Source distribution for ecotrace 1.7.1
File Size Uploaded Provenance Actions
ecotrace-1.7.1.tar.gz 187.0 kB Without provenance Details for ecotrace-1.7.1.tar.gz

Built distribution (wheel)

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

Total release size: 357.3 kB

Release files / ecotrace-1.7.1.tar.gz

Download URL ecotrace-1.7.1.tar.gz
Size 187.0 kB
Tags Source
SHA-256 checksum
How to use checksums
0abfdf8d1055f126b1b901644e367f9c3418cc9a722c511f608e88ce1b4b22c9
BLAKE2b-256 checksum
How to use checksums
98c1c0dac6ff5e9e2bb383f7af8cc3f0d380a0b2a94dcb424dd64e638fab964c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.1

Release files / ecotrace-1.7.1-py3-none-any.whl

Download URL ecotrace-1.7.1-py3-none-any.whl
Size 170.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
25651fe09da0ba2f7eeeeafa9e376e1c5bd7a5cb2b0f0a92ff096624baf6650c
BLAKE2b-256 checksum
How to use checksums
3938f60d43784f2176939bede2d84f19a0173311e43280715b1e99c96ac955d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.1

Security for ecotrace 1.7.1

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.

Release history Release notifications | RSS feed

This release

1.7.1 This release

2 release files No provenance

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