Skip to main content

GHSA Client

A Python client library for the GitHub Security Advisory (GHSA) API, providing structured access to security advisory data.

Features

  • Sync and async clients: GHSAClient for synchronous code, AsyncGHSAClient for async/await
  • Type-safe models: Full Pydantic models for GHSA data structures
  • Rate limiting: Built-in rate limit handling and retry logic
  • Flexible queries: Search advisories with various filters
  • Comprehensive data: Access to all GHSA fields including CVSS scores, CWE mappings, and package information

Installation

pip install ghsa-client

Quick Start

import logging
from ghsa_client import GHSAClient, GHSA_ID

# Set up logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

# Create client
client = GHSAClient(logger)

# Get a specific advisory
ghsa_id = GHSA_ID("GHSA-gq96-8w38-hhj2")
advisory = client.get_advisory(ghsa_id)

print(f"Advisory: {advisory.summary}")
print(f"Severity: {advisory.severity}")
print(f"CVSS Score: {advisory.cvss.score if advisory.cvss else 'N/A'}")

Usage

Authentication

The client automatically uses the GITHUB_TOKEN environment variable if available:

export GITHUB_TOKEN=your_github_token_here

Getting an Advisory

from ghsa_client import GHSAClient, GHSA_ID

client = GHSAClient(logger)
advisory = client.get_advisory(GHSA_ID("GHSA-gq96-8w38-hhj2"))

# Access advisory properties
print(advisory.summary)
print(advisory.severity)
print(advisory.published_at)
print(advisory.vulnerabilities)

Async Client

AsyncGHSAClient provides the same API using httpx.AsyncClient:

from ghsa_client import AsyncGHSAClient, GHSA_ID

async with AsyncGHSAClient() as client:
    advisory = await client.get_advisory(GHSA_ID("GHSA-gq96-8w38-hhj2"))

    async for adv in client.search_advisories(ecosystem="npm"):
        print(adv.summary)

Searching Advisories

# Search by ecosystem
advisories = client.search_advisories(ecosystem="npm")

# Search by severity
advisories = client.search_advisories(severity="high")

# Search by date range
advisories = client.search_advisories(published="2024-01-01..2024-12-31")

# Get all advisories for a year
advisories = client.get_all_advisories_for_year(2024)

Rate Limiting

The client automatically handles GitHub's rate limits:

# Check remaining rate limit
rate_limit = client.get_ratelimit_remaining()
print(f"Remaining requests: {rate_limit['resources']['core']['remaining']}")

# The client will automatically wait for rate limit reset when needed

Models

Advisory

The main model representing a GitHub Security Advisory:

from ghsa_client import Advisory

advisory: Advisory = client.get_advisory(ghsa_id)

# Core properties
advisory.ghsa_id          # GHSA_ID object
advisory.cve_id           # Optional CVE_ID object
advisory.summary          # str
advisory.severity         # str
advisory.published_at     # str (ISO date)
advisory.description      # Optional[str]

# Vulnerability data
advisory.vulnerabilities  # List[Vulnerability]
advisory.affected_packages # List[Package] (computed property)

# CVSS data
advisory.cvss             # Optional[CVSS]
advisory.cwes             # Optional[List[str]]

# Repository information
advisory.source_code_location # Optional[str]
advisory.repository_url   # str (property, raises if not found)

# References
advisory.references       # List[str]

GHSA_ID

Type-safe GHSA identifier with validation:

from ghsa_client import GHSA_ID, InvalidGHSAIDError

try:
    ghsa_id = GHSA_ID("GHSA-gq96-8w38-hhj2")
    print(ghsa_id.id)  # "GHSA-gq96-8w38-hhj2"
except InvalidGHSAIDError as e:
    print(f"Invalid GHSA ID: {e}")

CVE_ID

Type-safe CVE identifier with validation:

from ghsa_client import CVE_ID

cve_id = CVE_ID("CVE-2024-12345")
print(cve_id.id)  # "CVE-2024-12345"

Development

Setup

git clone https://github.com/valmarelox/ghsa-client.git
cd ghsa-client
pip install -e ".[dev]"

Running Tests

pytest

Code Formatting

black .
isort .

Type Checking

mypy src/ghsa_client

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or pull request on GitHub.

Changelog

See the releases page for a history of changes.

Download files

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

Source Distribution

ghsa_client-1.14.0.tar.gz (20.0 kB view details)

Uploaded Source

Built Distribution

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

ghsa_client-1.14.0-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

Details for the file ghsa_client-1.14.0.tar.gz.

File metadata

  • Download URL: ghsa_client-1.14.0.tar.gz
  • Upload date:
  • Size: 20.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ghsa_client-1.14.0.tar.gz
Algorithm Hash digest
SHA256 5797262cfc6c301807f4d94f79c883ea47f19fecc9058cc2ee82d91d262f90f1
MD5 c8a92d1c98787d2ee8d2e69718c7151f
BLAKE2b-256 dbf3d45381cd188d1d24d33c16139720d401d81778da43cd5d64a7132549db0d

See more details on using hashes here.

Provenance

The following attestation bundles were made for ghsa_client-1.14.0.tar.gz:

Publisher: publish.yml on Valmarelox/ghsa-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ghsa_client-1.14.0-py3-none-any.whl.

File metadata

  • Download URL: ghsa_client-1.14.0-py3-none-any.whl
  • Upload date:
  • Size: 18.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ghsa_client-1.14.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5a047d27a011cb447a10545669ef302b02d5e624a9b0d42362b94317976c335d
MD5 c3b5b1c9f727c96dc8608e3e4f46564c
BLAKE2b-256 e050ec69df79f02b36a504d90544bd13e7e4a752ab72194ba9473e971d44079e

See more details on using hashes here.

Provenance

The following attestation bundles were made for ghsa_client-1.14.0-py3-none-any.whl:

Publisher: publish.yml on Valmarelox/ghsa-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.14.0 This release

2 files

1.13.0

2 files

1.12.0

2 files

1.11.0

2 files

1.10.0

2 files

1.9.0

2 files

1.8.0

2 files

1.7.0

2 files

1.6.0

2 files

1.5.0

2 files

1.4.0

2 files

1.3.0

2 files

1.2.0

2 files

1.0.4

2 files

1.0.3

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

0.1.0

2 files

Supported by

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