Skip to main content

netgreener_sdk

Python SDK for NetGreener — the AI developer agent and runtime control layer for resource, cost, and environmental impact.

Integrate NetGreener into your own tools and pipelines: authenticate, manage projects, upload run evidence, and access reports that link code and releases to verified CPU/GPU, cost, energy, carbon, and water impact.

Thin Python client for the NetGreener HTTP API (/api/v1).

Full handbook (CLI + VS Code + SDK + CI): ../docs/PROGRAMMER_BOOKLET.md Same contracts as api_server routers; paths mirror netgreener_cli/netgreener/api_client.py with extra /features coverage.

Install

From the repo (editable):

pip install -e ./netgreener_sdk

Requires Python 3.10+ and requests.

Quick start

from netgreener_sdk import NetGreenerClient, APIError

client = NetGreenerClient(base_url="http://localhost:8000/api/v1")
client.login(email="you@example.com", password="…")
me = client.get_me()
print(me["email"])

# Project feature metadata (Parquet / path pointer)
row = client.post_project_feature_metadata(
    1,
    {"parquet_path": "/data/features.parquet", "feature_version": 1},
)

# Repo-aware project (git_url match order mirrors CLI)
project = client.get_or_create_project(
    "My ML repo",
    "/work/my-ml",
    git_url="https://github.com/acme/my-ml.git",
)

# Report AI summary credit quote (Phase 8d)
quote = client.quote_report_ai_summary(
    org_id=1,
    payload={
        "template": "sustainability",
        "scope_type": "org",
        "period_config": {
            "primary": {"from": "2026-04-01", "to": "2026-04-30"},
            "comparisons": [],
        },
    },
)
print(quote["total_credits"])

# Generate and download (Phase 8 SDK P2)
result = client.generate_report(
    1,
    {
        "template": "sustainability",
        "scope_type": "org",
        "period_config": {
            "primary": {"from": "2026-04-01", "to": "2026-04-30"},
            "comparisons": [],
        },
        "output_format": "both",
    },
)
report_id = result["report"]["report_id"]
pdf_bytes = client.download_report(1, report_id, format="pdf")

Base URL

Pass the API root including /api/v1, e.g. https://your-host/api/v1.

Auth

  • login(email, password); sets the bearer token on the client; response includes user, access_token, expires_in.
  • set_token(token); use an existing JWT.
  • get_access_token(); current token or None.
  • get_me(); GET /auth/me (requires valid token).

Feature metadata writes on the server require developer or admin; GET requires project access.

Projects & reports (Phase 3b)

Method HTTP
get_projects GET /projects
create_project POST /projects
update_project PUT /projects/{id}
get_or_create_project list + match by git_url → directory → name; create or sync
quote_report_ai_summary POST /organizations/{org_id}/reports/ai-summary/quote
preview_report / generate_report POST .../reports/preview / .../generate
get_report_history / download_report GET .../history / .../{report_id}/download
get_report_settings / update_report_settings schedule + cost assumptions
run_scheduled_report_now POST .../reports/schedule/run-now

Local analyze (--paths, analyze_local) stays in the netgreener CLI package, not the SDK.

See also

  • docs/CODEANALYZER_TO_API_SURFACE.md; which endpoints exist and how they map to CodeAnalyzer outputs.
  • docs/PLAN_INDEX.md; full product/engineering plan checklist.

Tests

From repo root:

python -m pytest netgreener_sdk/tests -q

Publish (CI)

Same PyPI token as the CLI : Azure Library group Package_credential, secret PYPI_API_TOKEN, must allow upload to both netgreener and netgreener_sdk.

Different pipeline and tag (not the CLI pipeline):

Package Pipeline Git tag PyPI name
CLI azure-pipelines-cli-publish.yml cli-v*.*.* netgreener
SDK azure-pipelines-sdk-publish.yml sdk-v*.*.* netgreener_sdk

Example SDK release: git tag sdk-v0.1.0 && git push origin sdk-v0.1.0

Pre-publish local build (recommended)

Before pushing the sdk-v... tag, verify the wheel/sdist build is clean:

python -m pip install --upgrade pip
python -m pip install build twine
python -m build netgreener_sdk
python -m twine check netgreener_sdk/dist/*

Release files for netgreener-sdk 0.1.3

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

Source distribution (sdist)

Source distribution for netgreener-sdk 0.1.3
File Size Uploaded
netgreener_sdk-0.1.3.tar.gz 11.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for netgreener-sdk 0.1.3
File Interpreter ABI Platform
netgreener_sdk-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 20.4 kB

Release files / netgreener_sdk-0.1.3.tar.gz

Download URL netgreener_sdk-0.1.3.tar.gz
Size 11.6 kB
Tags Source
SHA-256 checksum
How to use checksums
2fa73f3e4f262ea8d16de09d2a1dcfcc69dfe1abdba9708b183fe88ccca1c9a5
BLAKE2b-256 checksum
How to use checksums
c863744b3d9086e915621cdff7bdecb71683132511316b5a25ab12ecdcc7a276
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.11

Release files / netgreener_sdk-0.1.3-py3-none-any.whl

Download URL netgreener_sdk-0.1.3-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8b0081fa9301733c01cfac02b5af65f30f1d58af0a2f9aa6de1e10a6139c8eec
BLAKE2b-256 checksum
How to use checksums
0dab62a138c9594205f559a646e1058dc87fddf99b8d07882a2c287531b0159f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.11

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release 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