Python SDK
Integrate PatchOps Guard into your Python applications. Sync and async clients.
Installation
$ pip install patchguard-ai
Sync Client
For scripts, CLI tools, and synchronous applications.
from patchguard import PatchGuard
client = PatchGuard(api_key="pg_live_...")
# Scan a repository
result = client.scan.repo("https://github.com/your-org/your-repo")
print(f"CVEs found: {result.cves_total}")
# Scan a website
website = client.scan.website("https://example.com")
print(f"Score: {website.score}/100")
# Look up a package
pkg = client.scan.package(ecosystem="npm", name="express", version="4.17.0")
for vuln in pkg.vulns:
print(f" {vuln.cve_id} ({vuln.severity}) - {vuln.title}")
# Scan a Docker image
docker = client.scan.docker("nginx:1.25")
print(f"Critical: {docker.total_critical}, High: {docker.total_high}")
# Upload and scan a manifest file
manifest = client.scan.manifest("./package-lock.json")
print(f"Vulnerable packages: {manifest.packages_vulnerable}/{manifest.packages_total}")
# List findings with filters
findings = client.findings.list(severity="critical", status="open")
for f in findings:
print(f" {f.cve_id} in {f.package} - confidence: {f.confidence}")
Async Client
For FastAPI, asyncio, and high-throughput applications.
import asyncio
from patchguard import AsyncPatchGuard
async def main():
client = AsyncPatchGuard(api_key="pg_live_...")
# Parallel scans
repo, website, docker = await asyncio.gather(
client.scan.repo("https://github.com/your-org/your-repo"),
client.scan.website("https://example.com"),
client.scan.docker("nginx:1.25"),
)
print(f"Repo CVEs: {repo.cves_total}")
print(f"Website score: {website.score}")
print(f"Docker critical: {docker.total_critical}")
# Trigger AI repair for a finding
repair = await client.repair.create(
finding_id="find_abc123",
auto_pr=True,
)
print(f"Repair status: {repair.status}")
print(f"Confidence: {repair.confidence}/100")
await client.close()
asyncio.run(main())
Full API Reference
See the complete API documentation including all endpoints, request/response schemas, and authentication.
API Reference → /guide#api