Skip to main content

EcoTrace: High-precision carbon tracking engine for production Python. Function-level CPU/GPU emission measurement with 50ms continuous sampling, Boavizta TDP database, and audit-ready PDF reporting.

Project description

EcoTrace Logo

EcoTrace

High-Precision Energy and Emissions Instrumentation


v1.2.1 — Production/Stable Release. Bug fixes, secure HTTPS endpoints, dynamic USER_AGENT, class-level atexit session summaries, and ML tracker parameter alignment.

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 | 50+ Global Zones | AI-powered insights | Zero-configuration


PyPI - Version Python 3.9+ License: MIT Downloads Documentation Status VS Code Extension


[!TIP] VS Code Extension: Monitor application carbon footprint in real-time during development. Download here.


EcoTrace Demo

Function-level carbon measurement with real-time monitoring


Core Features in v1.2.1

Patch Release & Bug Fixes. v1.2.1 fixes Windows RAM detection, aligns ML logging columns, secures API endpoints, and prevents duplicate summaries.

  • EcoTraceML Tracking Engine — A dedicated context manager and decorator designed specifically for measuring carbon and energy footprint of machine learning and AI model training sessions.
  • Continuous Sampling — Uses asynchronous multi-threaded hardware metrics polling for high-frequency CPU/GPU/RAM monitoring.
  • Windows NVML Auto-Discovery — Dynamically resolves and injects NVML DLL paths (NVSMI and System32) to prevent load errors on Windows platforms.
  • NVIDIA Driver Robustness — Adds safe fallback UTF-8 decoding for newer NVIDIA drivers returning binary GPU names.
  • FPDF & Pylance Type Safety — Resolves strict type checking warnings by using positional parameters in PDF report cell generation.
  • Lazy Dependencies — Prevents startup ModuleNotFoundError by lazy-loading the optional google-generativeai package. See CHANGELOG.md.

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)

Measure any script without changing a single line of code:

ecotrace run my_script.py

Option 2: Programmatic Tracking (Library)

Decorate functions for granular instrumentation:

from ecotrace import EcoTrace

eco = EcoTrace(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")

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 Integration

Official GitHub Action

Enforce carbon budgets in your pipeline with our official GitHub Action. Add this to your .github/workflows/ci.yml:

- name: EcoTrace Carbon Gate
  uses: Zwony/ecotrace@v1.2.1
  with:
    budget: '10.0'
    region: 'US'

Manual CLI Integration

You can also run the gate manually:

ecotrace gate --budget 10.0

If total emissions exceed the budget, the gate fails with exit code 1 — preventing carbon-heavy code from being merged.


Why EcoTrace?

Feature EcoTrace v1.0 CodeCarbon CarbonTracker
Sampling Interval 50ms 15s Per Epoch
Isolation Process-scoped System-wide System-wide
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 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).

Documentation

Full documentation is available at ecotrace.readthedocs.io.


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 OzkalGitHub · ecotraceteam@gmail.com

MIT License — Use it however you like.

Developed for sustainable software development practices.

Project details


Download files

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

Source Distribution

ecotrace-1.2.1.tar.gz (171.9 kB view details)

Uploaded Source

Built Distribution

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

ecotrace-1.2.1-py3-none-any.whl (177.6 kB view details)

Uploaded Python 3

File details

Details for the file ecotrace-1.2.1.tar.gz.

File metadata

  • Download URL: ecotrace-1.2.1.tar.gz
  • Upload date:
  • Size: 171.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.1

File hashes

Hashes for ecotrace-1.2.1.tar.gz
Algorithm Hash digest
SHA256 98de2ff984376a220c28900d3768796c0b9f836b5e94817890304762eec49b9d
MD5 8bffa2a114e0769cf7a0b16c766c0ea2
BLAKE2b-256 0a3f4223f8249e7448ff61aa41437bcff74dc7d0f83720f9e68069968c4b520e

See more details on using hashes here.

File details

Details for the file ecotrace-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: ecotrace-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 177.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.1

File hashes

Hashes for ecotrace-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9baa7233a695fd9131e31c94af1410aa1a4f12af45f4289a6d85c49e8a00e519
MD5 8248c3642d6658854cb831a19d9d6751
BLAKE2b-256 31d24e9e9ffde2a944d352f149dd1557ca2f2a73ec078120d24b1eb6c2a08572

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page