Skip to main content

Official Python SDK for Precogs AI - Security-first code analysis

Project description

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.

Project details


Download files

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

Source Distribution

precogs_sdk-0.1.1.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

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

precogs_sdk-0.1.1-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file precogs_sdk-0.1.1.tar.gz.

File metadata

  • Download URL: precogs_sdk-0.1.1.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for precogs_sdk-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0f467e9a9e96f9131b72c0e68afe70f6039f66e71e2cea70f75a7a4efafbebfb
MD5 7a534a6332b665a81d8f4f21fb1988a4
BLAKE2b-256 ae3dfbdda187da0dfde2b8ee1fba14bafc6f58df93188768a87e9e15248c5b66

See more details on using hashes here.

File details

Details for the file precogs_sdk-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: precogs_sdk-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for precogs_sdk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b807d1614c35b5fefbc9d8879179a2f67b2aca68c8ccc2480c9f6b650c4bfed1
MD5 be7786d4e44c461d5267f56cc1ddb840
BLAKE2b-256 a8212d200e36a605fb31a8923dd75159f8099b59bb763d886363a15dc47acfa3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page