Skip to main content
Yanked

This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
Consider using release 0.4.21 instead.
Reason given by maintainers: Crashes on all invocations; fixed in 0.4.21 (CLEANLIB-629)

cleanlib-sdk

CleanLibrary Python SDK — asyncio + httpx; mirrors the Rust cleanlib-client HTTP surface and the JavaScript @cleanstart/cleanlib-sdk sister-shape.

Status: v0.4.7 — production-ready.

Install

pip install cleanlib-sdk

Requires Python 3.10+. Depends on httpx>=0.27 and pydantic>=2.

Overview — per-domain client triad (v0.4.2+)

v0.4.2 split the SDK into three per-domain HTTP clients, each pointed at its own CleanLibrary surface:

Client Endpoint (default) Purpose
HttpVerdictClient https://cleanapp.clnstrt.dev App customer-verdict surface — fetch_verdict / scan / audit / policy_preview / risk_accept
HttpRemediationClient DEFAULT_REMEDIATION_BASE_URL (https://cleanlib-enrich.clnstrt.dev) Sparse 7-block /remediation responses
HttpEnrichClient DEFAULT_ENRICH_BASE_URL (https://cleanlib-enrich.clnstrt.dev) 8-verb cleanlib-enrich cascade — get_exploitability / get_exploitability_bulk / get_epss / get_kev / get_advisories / get_enrich / get_library_verdict / bulk_packages_check

The legacy Client (flat-method) still ships for source-compat with v0.4.0 callers and emits DeprecationWarning on __init__; scheduled removal in v1.0.0. New integrations should use the per-domain triad.

Usage — verdict client

import asyncio
from cleanlib_sdk import HttpVerdictClient, PolicyDenyError, RiskAcceptanceRequiredError

async def main() -> None:
    async with HttpVerdictClient(
        base_url="https://cleanapp.clnstrt.dev",
        api_key="clk_std_...",   # opaque CleanLibrary access key
    ) as c:
        try:
            v = await c.fetch_verdict("npm", "lodash", "4.17.21")
            print(f"{v.decision} composite_score={v.composite_score}")
            print(f"reasoning: {v.reasoning}")
        except PolicyDenyError as e:
            print(f"DENIED [{e.reason_code}]: {e.message}")
        except RiskAcceptanceRequiredError as e:
            print(f"RISK ACCEPT REQUIRED: {e.message}")
            if e.docs_url:
                print(f"see: {e.docs_url}")

asyncio.run(main())

Usage — enrich cascade

import asyncio
from cleanlib_sdk import (
    HttpEnrichClient,
    epss_found, kev_found,
    EXPLOITABILITY_BULK_CAP,
)

async def main() -> None:
    async with HttpEnrichClient(api_key="clk_std_...") as e:
        # KEV / EPSS return a discriminated union — one of *_found / *_not_found.
        kev = await e.get_kev("CVE-2021-44228")
        if kev_found(kev):
            print(f"KEV listed: due_date={kev.due_date}")

        epss = await e.get_epss("CVE-2021-44228")
        if epss_found(epss):
            print(f"EPSS score={epss.score} percentile={epss.percentile}")

        # Bulk: server caps at EXPLOITABILITY_BULK_CAP (100) per request.
        exp = await e.get_exploitability_bulk([
            "CVE-2021-44228", "CVE-2022-22965", "CVE-2023-4863",
        ])
        for cve in exp.results:
            print(cve.cve_id, cve.availability)

asyncio.run(main())

Usage — remediation

import asyncio
from cleanlib_sdk import HttpRemediationClient

async def main() -> None:
    async with HttpRemediationClient(api_key="clk_std_...") as r:
        rem = await r.get_remediation("npm", "lodash", "4.17.15")
        # Sparse 7-block: any block may be absent (RemediationOrAbsent).
        if rem.recommended_version is not None:
            print(f"upgrade to {rem.recommended_version.version}")

asyncio.run(main())

Public API surface

Everything below is exported from the top-level cleanlib_sdk package and covered by __all__ (verified against dir(cleanlib_sdk) at release-cut per CLEANLIB-83). New symbols are grouped by the version they were introduced in.

v0.4.7 — Verdict.decision auto-derived

  • Verdict.decision is now auto-derived at the type layer (CLEANLIB-294) — consumers no longer need to re-run derive_status on a raw Verdict; the field is populated from the envelope substance + freshness precedence at parse time.

v0.4.6 — envelope emit

  • verdict_to_envelope_v1(verdict) -> dict — canonical Verdict→envelope packer per CLEANLIB-48. Sister-shape of the sdk-js emitter; the fixture-driven contract test in tests/verdict_to_envelope_contract.py keeps both SDKs byte-identical.

v0.4.5 — previous-verdict parity

  • PreviousVerdict — envelope carries the prior verdict when a re-scan changes the decision; enables audit-log diff view.

v0.4.4 — customer-state taxonomy (CLEANLIB-178)

  • CustomerState — enum mirroring cleanlib-client/src/customer_state.rs.
  • Tier — customer tier enum (FREE / STD / PRO / …).
  • ALL_VERDICT_SOURCES — canonical registry of verdict-source strings (used by cross-SDK contract test to guard against silent drift).

v0.4.3 — brand/metadata sanitize

Pyproject brand cleanup; no new symbols.

v0.4.2 — enrich cascade + F4 default-flip

Clients:

  • HttpVerdictClient — App customer-verdict surface (completes the triad; the v0.4.1 split shipped remediation + enrich).
  • HttpEnrichClient — 8-verb cleanlib-enrich cascade; defensive wrappers (advisories double-parse + dedup; cve_id ↔ cveId normalization; sparse-by-design tolerance).

Constants:

  • DEFAULT_ENRICH_BASE_URLhttps://cleanlib-enrich.clnstrt.dev.
  • DEFAULT_REMEDIATION_BASE_URL — F4-flipped to https://cleanlib-enrich.clnstrt.dev (was the vva URL in v0.4.1). Consumers passing an explicit base_url= are unaffected.
  • EXPLOITABILITY_BULK_CAP — server-side cap on get_exploitability_bulk batch size.
  • REMEDIATION_CACHE_TTL_SECS — default TTL used by the remediation client's in-process cache.

Enrich wire-shapes:

  • AdvisoryRow, AdvisorySeverity — advisories.
  • AvailabilityFlag, ExploitabilityAvailability, ExploitabilityResponse — exploitability triage.
  • EpssResponse, EpssOrNotFound, epss_found, epss_not_found — EPSS with found/not-found discriminated union + helpers.
  • KevResponse, KevOrNotFound, kev_found, kev_not_found — KEV with found/not-found discriminated union + helpers.
  • EnrichResponse, LibraryVerdictResponse — top-level cascade responses.
  • BulkPackageRef, BulkPackageResult, BulkPackagesCheckResponsebulk_packages_check request/response shapes.

v0.4.1 — contract enforcement + remediation client

  • HttpRemediationClient — sparse 7-block /remediation responses.
  • RemediationBlock, RemediationResponse, RemediationOrAbsent — remediation wire-shapes.
  • ReasonCode — 15-entry canonical registry (Enum).
  • ALL_REASON_CODES — read-only tuple of every registered reason code.
  • VERDICT_ENVELOPE_V1_SCHEMA, SCHEMA_ID, STATUS_ENUM, AVAILABILITY_ENUM — JSON-Schema mirror + enum sets.
  • derive_status(envelope) -> StatusResult — canonical algorithm per App dispatch §4 binding contract (substance precedence + freshness override).
  • StatusResult — output shape of derive_status.
  • Client — legacy flat-method class; emits DeprecationWarning on __init__ (v1.0.0 removal).

v0.4.0 — verb cascade + rich-data ripple

Response types shared across the triad:

  • Verdict — canonical verdict envelope with attestation.
  • Attestation, SignedAttestation — signed provenance.
  • RecommendedVersion, PackageRisk, PackageRef — rich-data fields.
  • ScanResult, ScanResponsescan endpoint.
  • AuditWindow, AuditWindowResponseaudit endpoint.
  • PolicyPreviewResult, PolicyPreviewResponsepolicy preview.
  • RiskAcceptResponserisk-accept submission response.

Sub-modules

Everything the flat surface re-exports also lives in a namespaced sub-module — import from either. Use the sub-module path when you need to disambiguate against a same-named symbol from a sister SDK.

  • cleanlib_sdk.client — legacy Client (deprecated).
  • cleanlib_sdk.customer_state — v0.4.4 state taxonomy.
  • cleanlib_sdk.derive_statusderive_status + StatusResult.
  • cleanlib_sdk.errors — every exception in the hierarchy below.
  • cleanlib_sdk.http — the three Http*Clients, wire-shapes, constants, helper functions.
  • cleanlib_sdk.reason_codesReasonCode, ALL_REASON_CODES.
  • cleanlib_sdk.schemaVERDICT_ENVELOPE_V1_SCHEMA, enum sets.
  • cleanlib_sdk.transport — internal httpx.AsyncClient wrapper (not re-exported at the top level; used by all three Http*Clients).
  • cleanlib_sdk.types — response dataclasses.
  • cleanlib_sdk.verdict_to_envelopeverdict_to_envelope_v1.

Error hierarchy

All errors descend from CleanLibraryError. Subclasses:

Exception HTTP Triggered by
PolicyDenyError 403 / 451 POLICY_DENY_VERDICT / POLICY_DENY_RULE_EXPLICIT
IntegrityFailureError 403 INTEGRITY_FAILURE
RateLimitExceededError 429 tier-throttled; carries retry_after_seconds
RiskAcceptanceRequiredError 403 RISK_ACCEPTANCE_REQUIRED
AuthenticationError 401 / 403 KEY_INVALID / KEY_EXPIRED / KEY_SCOPE_INSUFFICIENT
InsufficientDataError 403 INSUFFICIENT_DATA_FAIL_CLOSED
PackageNotFoundError 404 not in catalog + ingest declined
ServerError 5xx retryable on 502/503/504
TransportError network / TLS / timeout / DNS
ParseError response body shape mismatch

Development

pip install -e ".[dev]"
pytest
ruff check .

Contract tests (tests/contract.py, tests/customer_state_contract.py, tests/verdict_to_envelope_contract.py) load fixtures from cleanlib-contract-fixtures and assert byte-identical behavior against the sdk-js sister — do not skip these; a divergence is a wire-shape regression.

Cross-references

License

Proprietary — CleanStart.

Download files

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

Source Distribution

cleanlib_sdk-0.4.8.tar.gz (38.2 kB view details)

Uploaded Source

Built Distribution

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

cleanlib_sdk-0.4.8-py3-none-any.whl (48.1 kB view details)

Uploaded Python 3

File details

Details for the file cleanlib_sdk-0.4.8.tar.gz.

File metadata

  • Download URL: cleanlib_sdk-0.4.8.tar.gz
  • Upload date:
  • Size: 38.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.6

File hashes

Hashes for cleanlib_sdk-0.4.8.tar.gz
Algorithm Hash digest
SHA256 fd1d351d2e463128a259ac26fa93b6517c9a11762123bed266694060c88716a9
MD5 1810f48b61fd3e15f2cba695f76ea4c4
BLAKE2b-256 bd93d526c0ad6efed62fe422c801c42bdb8c87d33edb1af6595cd45670e2fa8b

See more details on using hashes here.

File details

Details for the file cleanlib_sdk-0.4.8-py3-none-any.whl.

File metadata

  • Download URL: cleanlib_sdk-0.4.8-py3-none-any.whl
  • Upload date:
  • Size: 48.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.6

File hashes

Hashes for cleanlib_sdk-0.4.8-py3-none-any.whl
Algorithm Hash digest
SHA256 5068feb1604f2a4588c2e51489babeb16f17813348cf370e4bcd39e81559ced4
MD5 8b4e56cb07838d123264ca641d38d1de
BLAKE2b-256 7064018967f731ac2f5a592b13e11d77cbd668a8df380091777df8251fe8edae

See more details on using hashes here.

Release history Release notifications | RSS feed

0.4.21

2 files

0.4.20

2 files

0.4.19

2 files

0.4.18

2 files

0.4.17

2 files

0.4.16

2 files

0.4.15

2 files

0.4.14

2 files

0.4.13

2 files

0.4.12

2 files

0.4.11

2 files

0.4.10

2 files

0.4.9

2 files

This release

0.4.8 This release

2 files

0.4.7

2 files

0.4.6

2 files

0.4.5

2 files

0.4.4

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 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