Metadata-Version: 2.4
Name: netgreener
Version: 0.4.5
Summary: NetGreener CLI: AI developer agent and runtime control for measuring and reducing compute cost, energy, carbon, and water across the software lifecycle
Author-email: Saeed Khazaee <saeed@netgreener.com>
License-Expression: LicenseRef-Proprietary
Requires-Python: <3.15,>=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.31
Requires-Dist: click>=8.1
Requires-Dist: psutil>=5.9
Requires-Dist: rich>=13.0
Requires-Dist: radon>=6.0
Requires-Dist: openai>=1.55.0
Requires-Dist: nvidia-ml-py>=12.535
Requires-Dist: pandas>=1.5
Requires-Dist: numpy>=1.24
Requires-Dist: scipy>=1.10
Requires-Dist: scikit-learn>=1.2
Requires-Dist: Pillow>=10.0
Requires-Dist: pyyaml>=6.0
Requires-Dist: jsonschema<5,>=4.18
Requires-Dist: rfc3339-validator<1,>=0.1.4
Provides-Extra: dev
Requires-Dist: pytest>=7; extra == "dev"
Requires-Dist: pytest-mock>=3; extra == "dev"
Provides-Extra: packaging
Requires-Dist: pyinstaller>=6.0; extra == "packaging"
Provides-Extra: gpu
Provides-Extra: data
Provides-Extra: image
Provides-Extra: full
Dynamic: license-file

# netgreener CLI

**NetGreener** — the AI developer agent and runtime control layer for reducing compute costs, energy use, and environmental impact.

This CLI is the command-line entry point for that continuous system: guide resource-aware development, forecast impact before merge, measure actual CPU/GPU, cost, energy, carbon, and water at runtime, and feed verified results back into the next release.

Use it for run analysis, CI efficiency checks, upload, and feature registry APIs.

## Install

From this folder:

```bash
pip install -e .
```

## Quick start

```bash
netgreener login --email you@example.com
netgreener status
netgreener config
```

## Tenant monitoring (per downstream B2B client company)

Monitor spend and anomalies **per customer org** (`organization_id`), not per end-user.

**Recommended — bind in auth (no `NETGREENER_TENANT_*` env needed):**

```python
from netgreener.tenant_attribution import set_tenant_id

async def get_current_user(...):
    user = ...  # your verified JWT / session
    set_tenant_id(str(user.organization_id), source="jwt_claim:organization_id")
    return user
```

Register `add_netgreener_middleware(app)` and attach that dependency on metered routes.

**Celery workers:** pass `organization_id` in task kwargs; worker env `NETGREENER_TENANT_SOURCE=task_kwarg`, `NETGREENER_TENANT_TASK_KWARG=organization_id`.

Docs: [`../docs/TENANT_ATTRIBUTION_V0.md`](../docs/TENANT_ATTRIBUTION_V0.md) · [`../docs/DEEDDEX_TENANT_MONITORING_INTEGRATION.md`](../docs/DEEDDEX_TENANT_MONITORING_INTEGRATION.md).

## Web services (FastAPI)

| Goal | Doc / command |
|------|----------------|
| **Customers:** integrate into **their** FastAPI app | [`../docs/SERVICE_RUNTIME_INTEGRATION.md`](../docs/SERVICE_RUNTIME_INTEGRATION.md) |
| **Downstream B2B tenant monitoring** (per client company) | [`../docs/TENANT_ATTRIBUTION_V0.md`](../docs/TENANT_ATTRIBUTION_V0.md) · [`../docs/DEEDDEX_TENANT_MONITORING_INTEGRATION.md`](../docs/DEEDDEX_TENANT_MONITORING_INTEGRATION.md) |
| **NetGreener team:** test on `api_server` | [`../docs/DOGFOODING_API_SERVER_RUNTIME.md`](../docs/DOGFOODING_API_SERVER_RUNTIME.md) |
| CI smoke probe | `netgreener run <starter.py> . --service-run` |
| Workload YAML | [`../docs/SERVICE_PROBE_WORKLOAD.md`](../docs/SERVICE_PROBE_WORKLOAD.md) |
| Full CLI reference | [`../docs/PROGRAMMER_BOOKLET.md`](../docs/PROGRAMMER_BOOKLET.md) |
| Code map / related files | [`../docs/CODE_MAP_AND_PROJECT_INDEX.md`](../docs/CODE_MAP_AND_PROJECT_INDEX.md) |
| Errors & troubleshooting | [`../docs/TROUBLESHOOTING_AND_ERRORS.md`](../docs/TROUBLESHOOTING_AND_ERRORS.md) |

## Features API commands

These commands wrap `api_server/routers/features.py` under `/api/v1/features`.

### 1) Project feature metadata (artifact pointer)

Use this to register the project-level path/URI for extracted features (e.g. Parquet or JSON bundle pointer).

```bash
netgreener features metadata get 1
netgreener features metadata register 1 --parquet-path /data/features.parquet --feature-version 1
netgreener features metadata update 1 --parquet-path /data/features_v2.parquet
netgreener features metadata delete 1 -y
```

### 2) Feature collection inputs (`featurecollectioninput`)

```bash
netgreener features inputs list --project-id 1
netgreener features inputs list-project 1
netgreener features inputs create 1 --feature-name avg_complexity --value 0.42
netgreener features inputs get 123
netgreener features inputs update 123 --value 0.43
netgreener features inputs delete 123 -y
```

### 3) Feature definitions (`featuredefinition`)

```bash
netgreener features definitions list --data-type float --source-type code
netgreener features definitions create test_feature_x --description "temp" --data-type float --source-type code --min-value 0 --max-value 1
netgreener features definitions get test_feature_x
netgreener features definitions update test_feature_x --description "temp2" --max-value 10
netgreener features definitions delete test_feature_x -y
```

## Auth / role notes

- `GET` endpoints generally require an authenticated active user with access.
- write operations (`POST`/`PUT`/`DELETE`) in features routes require **developer** or **admin**.

## Related docs

- [`../docs/SERVICE_RUNTIME_INTEGRATION.md`](../docs/SERVICE_RUNTIME_INTEGRATION.md) : customers: **their** FastAPI app
- [`../docs/DOGFOODING_API_SERVER_RUNTIME.md`](../docs/DOGFOODING_API_SERVER_RUNTIME.md) : internal `api_server` only
- [`../docs/SERVICE_PROBE_WORKLOAD.md`](../docs/SERVICE_PROBE_WORKLOAD.md) : `--service-run`, workload YAML
- [`../docs/PROGRAMMER_BOOKLET.md`](../docs/PROGRAMMER_BOOKLET.md) : full handbook
- `../docs/API_ENDPOINTS_CLI_IDE.md`
- `../docs/CODEANALYZER_TO_API_SURFACE.md`
- `../docs/PLAN_INDEX.md`

## SDK delegation note

The CLI API client (`netgreener/api_client.py`) delegates to `netgreener_sdk` when that package is available in the environment, while keeping HTTP fallback for compatibility with existing setups.

## Shared runtime contracts

The admitted Python Runtime profile, thin TCK adapter, and honest production-gap
ledger live in [`conformance/`](conformance/README.md). The immutable lock pins a
contracts revision published on `main`, which enables shared TCK evidence generation
but does not claim feature parity. Both Observation v1 actions currently report
unsupported because the CLI's production IPC and durable-queue boundaries implement
older, different contracts.

## Smoke test (end-to-end features flow)

Use one existing project id and a temporary feature name.

```bash
# 0) prerequisites
netgreener status
netgreener features metadata get 2

# 1) feature definition lifecycle
netgreener features definitions create smoke_feature_x --description "smoke" --data-type float --source-type code --min-value 0 --max-value 10
netgreener features definitions get smoke_feature_x
netgreener features definitions update smoke_feature_x --description "smoke-updated" --max-value 100
netgreener features definitions list --data-type float --source-type code

# 2) feature input lifecycle (for an existing project, e.g. 2)
netgreener features inputs create 2 --feature-name smoke_feature_x --value 0.42
netgreener features inputs list --project-id 2
# Capture input_id from output, then:
netgreener features inputs get <input_id>
netgreener features inputs update <input_id> --value 0.43
netgreener features inputs delete <input_id> -y

# 3) cleanup definition (must be after deleting all inputs that reference it)
netgreener features definitions delete smoke_feature_x -y
```

Expected outcomes:
- create/get/update/list commands return JSON objects/lists (HTTP 200/201 paths)
- delete commands return success payloads
- deleting a definition before deleting referencing inputs returns HTTP 400 by design

### Automated smoke test (one command)

```bash
python -m pytest tests/test_features_cli.py -k smoke_lifecycle -q
```

### Automated failure-path tests (one command)

```bash
python -m pytest tests/test_features_cli.py -k "handles_" -q
```

## PyPI publish (release maintainer)

PyPI distribution name is **`netgreener`** (see `pyproject.toml` `[project] name`).

Before tagging a release:

```bash
python -m pip install --upgrade pip
python -m pip install build twine
python -m build netgreener_cli
python -m twine check netgreener_cli/dist/*
```

Azure DevOps publishes on tags `cli-v*.*.*` via `azure-pipelines-cli-publish.yml`, using the same `PYPI_API_TOKEN` secret as the SDK publish pipeline (Library variable group `Package_credential`).
