Skip to main content

Precogs SDK

Official Python SDK for the Precogs AI security platform.

Installation

pip install precogs-sdk

Quick Start

from precogs import PrecogsClient

# Initialize with your API key
client = PrecogsClient(api_key="pk_live_xxxxxxxxxxxx")

# Or use environment variable
# export PRECOGS_API_KEY=pk_live_xxxxxxxxxxxx
client = PrecogsClient()

# List your projects
projects = client.projects.list()
for project in projects:
    print(f"Project: {project['name']}")

# Trigger a code scan
scan = client.scans.trigger_code_scan(project_id="proj_123")
print(f"Scan started: {scan['id']}")

# Get vulnerabilities
vulns = client.vulnerabilities.list(severity="critical")
for vuln in vulns:
    print(f"[{vuln['severity']}] {vuln['title']}")

Features

  • Code Security Scanning - SAST analysis for 20+ languages
  • Dependency Scanning - SCA for npm, pip, maven, etc.
  • IaC Scanning - Terraform, CloudFormation, Kubernetes
  • Container Scanning - Docker image vulnerability detection
  • AI-Powered Fixes - Get suggested code fixes for vulnerabilities

API Reference

Projects

# List all projects
projects = client.projects.list()

# Get a specific project
project = client.projects.get("proj_123")

# Create a new project
project = client.projects.create(
    name="My App",
    repo_url="https://github.com/org/repo",
    provider="github",
    branch="main"
)

Scans

# Trigger different scan types
scan = client.scans.trigger_code_scan(project_id="proj_123")
scan = client.scans.trigger_dependency_scan(project_id="proj_123")
scan = client.scans.trigger_iac_scan(project_id="proj_123")
scan = client.scans.trigger_container_scan(
    project_id="proj_123", 
    image="nginx:latest"
)

# Check scan status
status = client.scans.get_status(scan_id="scan_456")

# Get scan results
results = client.scans.get_results(scan_id="scan_456")

Vulnerabilities

# List vulnerabilities with filters
vulns = client.vulnerabilities.list(
    project_id="proj_123",
    severity="high",
    status="open"
)

# Get vulnerability details
vuln = client.vulnerabilities.get("vuln_789")

# Get AI-generated fix
fix = client.vulnerabilities.get_ai_fix("vuln_789")
print(fix['suggestedCode'])

# Update status
client.vulnerabilities.update_status(
    vuln_id="vuln_789",
    status="fixed",
    reason="Patched in v2.1.0"
)

Dashboard

# Get overall security metrics
overview = client.dashboard.get_overview()

# Get severity distribution
distribution = client.dashboard.get_severity_distribution()

# Get vulnerability trend
trend = client.dashboard.get_trend(days=30)

Error Handling

from precogs import PrecogsClient, AuthenticationError, RateLimitError

try:
    client = PrecogsClient(api_key="pk_live_xxx")
    projects = client.projects.list()
except AuthenticationError:
    print("Invalid API key")
except RateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after} seconds")

Environment Variables

Variable Description
PRECOGS_API_KEY Your Precogs API key

License

MIT License - see LICENSE for details.

Metadata

Release files for precogs-sdk 0.1.2

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

Source distribution (sdist)

Source distribution for precogs-sdk 0.1.2
File Size Uploaded
precogs_sdk-0.1.2.tar.gz 6.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for precogs-sdk 0.1.2
File Interpreter ABI Platform
precogs_sdk-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 15.4 kB

Release files / precogs_sdk-0.1.2.tar.gz

Download URL precogs_sdk-0.1.2.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
39318b228b2b04f8b916e596d94a20a2114a8f2d7b8e518efb23854734c34424
BLAKE2b-256 checksum
How to use checksums
370834799c03854a2a8faafc09a8ae0c7e23bc5f7a765480ebc788b37dffe551
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.6

Release files / precogs_sdk-0.1.2-py3-none-any.whl

Download URL precogs_sdk-0.1.2-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bcd36b26a89d3378678599173c41a9a2bb508b3509ed54f9ee46b618510a3627
BLAKE2b-256 checksum
How to use checksums
c20c4fed77a254578d67ff19f1bf60b0e3c7c0c9220d1f2699709273ce1e4319
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.6

Release history Release notifications | RSS feed

This release

0.1.2 This release

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