Python API
cloudg is a library first. The CLI is a thin layer over CloudGEngine, so anything a command does you can do from Python, one phase at a time if you like.
Start here¶
Most programs need three names, all importable from the package root: CloudGConfig to say what to collect, CloudGEngine to run it, and the result object that comes back.
No credentials and no scanner binaries: point the engine at scanner output produced elsewhere.
from cloudg import CloudGConfig, CloudGEngine
engine = CloudGEngine(CloudGConfig())
result = engine.run_from_reports_sync(
{"trivy": ["./trivy.json"], "checkov": ["./results_json.json"]},
output_dir="./reports",
)
print(result.total_findings, result.severity_breakdown)
for f in result.findings:
print(f.severity.value, f.source_tool, f.title)
Read-only credentials and the aws extra. No scanner runs.
from cloudg import CloudGConfig, CloudGEngine
config = CloudGConfig(providers=["aws"])
config.aws.profile = "audit"
config.aws.regions = ["ALL"]
inventory = CloudGEngine(config).map_inventory_sync(output_dir="./reports")
print(inventory.summary["total_assets"], "assets")
print(inventory.summary["internet_exposed"], "internet-exposed")
What cloudg run does: collect, scan, analyse and report.
How the pieces fit¶
flowchart LR
CFG["CloudGConfig"] --> ENG["CloudGEngine"]
ENG -->|collect| ASSETS["CloudAsset, NetworkEdge"]
ENG -->|scan or ingest| FIND["Finding"]
ASSETS --> GB["GraphBuilder"]
GB --> RA["ReachabilityAnalyzer"]
ASSETS --> ONT["CloudOntology, RAGExporter"]
FIND --> NORM["FindingsNormaliser"]
RA --> NORM
NORM --> RES["PipelineResult"]
ENG -->|map_inventory| IM["InventoryMapper"]
IM --> IR["InventoryResult"]
IR --> DG["DependencyGraph"]
Each box is a page below. The engine wires them together, but every one of them also works on its own: build a graph from assets you loaded yourself, normalise findings from a CMDB export, or link assets that came from your own collector.
Reference¶
Engine¶
-
The engine behind
cloudg run,cloudg ingestandcloudg map: the whole pipeline in one call, or each phase yourself. -
The pydantic model behind
config.yaml. Build it in code, load it from a file, or both. -
PipelineResult,CollectionResultandAnalysisResult: what the engine hands back. -
Six optional callbacks that report phases, findings, results and failures during a run.
-
The
CloudGErrorhierarchy, strict mode for the scanner wrappers andraise_for_errors().
Inventory¶
-
Maps what is deployed and how it connects, then overlays scanner findings on the map.
-
The map as one object: assets, edges, summary, dependency analysis, save and load.
-
Turns a flat list of assets from any source into a connected map.
-
What an asset needs, and what breaks if it goes away.
Graph¶
-
Assets and edges as a NetworkX
DiGraph: attack paths, centrality, exports. -
What the internet can reach, along the edges traffic can actually take.
-
An rdflib graph with 64 typed relations, exported as RDF and queried with SPARQL.
-
Text chunks with metadata, ready to embed for retrieval-augmented generation.
Findings¶
-
Findings from any number of scanners, merged, rescored, sorted and mapped to controls.
-
Native Prowler, ScoutSuite, Checkov and Trivy output as
Findingobjects. -
The pydantic models every part of cloudg exchanges.
Extend¶
-
Ship a collector or a scanner as its own package;
PluginRegistryfinds it. -
Your own cloud API calls through cloudg's rate limits, circuit breakers and retry budget.
-
The MCP catalog as a Python object: call it in-process, mount it, or export it.
Conventions¶
- Signatures, parameter tables and the "source" links on these pages are generated from the code at build time, so they always match the release the site was built from. The prose and the examples above each reference are written by hand.
- Methods that end in
_syncwrap the async method of the same name inasyncio.run(). Use them from scripts; inside a running event loop,awaitthe async method. - Everything cloudg raises on purpose derives from
CloudGError. See Exceptions.