Skip to main content

Canary SDK for Python - Dependency vulnerability scanning

Project description

roselabs-canary

Official Python SDK for Canary - Dependency vulnerability scanning by Rose Labs.

Installation

pip install roselabs-canary
# or
poetry add roselabs-canary
# or
uv add roselabs-canary

Quick Start

from roselabs_canary import Canary

canary = Canary(
    api_key="your-api-key",
    app_id="your-app-id",
)

result = canary.submit_scan(
    lockfiles=[
        {"filename": "requirements.txt", "content": open("requirements.txt").read()},
    ]
)

print(f"Found {result.vulnerabilities.total} vulnerabilities")
print(f"View details: {result.scan_url}")

API Reference

Canary(api_key, app_id, api_url=None, timeout=30)

Create a new Canary client.

canary = Canary(
    api_key="your-api-key",     # Required
    app_id="your-app-id",       # Required
    api_url="https://...",      # Optional (defaults to canary.roselabs.io)
    timeout=30,                 # Optional
)

canary.submit_scan(lockfiles, commit_sha=None, branch=None)

Submit lockfiles for vulnerability scanning.

from roselabs_canary import Canary, Lockfile

# Using dict
result = canary.submit_scan(
    lockfiles=[
        {"filename": "poetry.lock", "content": "..."},
    ],
    commit_sha="abc123",
    branch="main",
)

# Using Lockfile dataclass
result = canary.submit_scan(
    lockfiles=[
        Lockfile(filename="poetry.lock", content="...", path="backend/poetry.lock"),
    ]
)

Returns a ScanResult:

@dataclass
class ScanResult:
    scan_id: str
    app_id: str
    status: str  # 'completed', 'pending', or 'failed'
    vulnerabilities: VulnerabilityCounts
    scan_url: str
    details: list[Vulnerability] | None

@dataclass
class VulnerabilityCounts:
    critical: int
    high: int
    medium: int
    low: int
    total: int

canary.get_scan(scan_id)

Retrieve details of a previous scan.

result = canary.get_scan("scan-id-here")

Supported Lockfiles

Package Manager Lockfile
npm package-lock.json
yarn yarn.lock
pnpm pnpm-lock.yaml
pip requirements.txt
pipenv Pipfile.lock
poetry poetry.lock
uv uv.lock
cargo Cargo.lock
go modules go.sum

Error Handling

from roselabs_canary import Canary, CanaryError

try:
    result = canary.submit_scan(lockfiles=[...])
except CanaryError as e:
    print(f"Canary error: {e}")
    print(f"Status code: {e.status_code}")

Context Manager

The client can be used as a context manager to ensure proper cleanup:

with Canary(api_key="...", app_id="...") as canary:
    result = canary.submit_scan(lockfiles=[...])

CI/CD Integration

For CI/CD pipelines, consider using the Canary GitHub Action instead for simpler setup.

License

MIT

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

roselabs_canary-1.0.1.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

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

roselabs_canary-1.0.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file roselabs_canary-1.0.1.tar.gz.

File metadata

  • Download URL: roselabs_canary-1.0.1.tar.gz
  • Upload date:
  • Size: 16.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for roselabs_canary-1.0.1.tar.gz
Algorithm Hash digest
SHA256 7485ebbf184900d8babb44667743923798cd68ccb6838979c791e397c1e2e340
MD5 1757296c96b8f5972fba6cbcac959e91
BLAKE2b-256 be046b59a698735683a1850988907d383d09f7c7d9980591c05e2f371dace48e

See more details on using hashes here.

File details

Details for the file roselabs_canary-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: roselabs_canary-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for roselabs_canary-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5f042a670e74dcc35aeba98af2d97c27e0e9775a90f6b9845bad1fd89cecffa9
MD5 80cdefd957172779582ed2e139868563
BLAKE2b-256 f4f3cb2c89053313b0055024498501de978b8a680bc70fa524e6ab5b4147974b

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