Skip to main content

Typed Python client and CLI for FIRST EPSS (Exploit Prediction Scoring System) API

Project description

EPSS Client v2.0

Typed Python client and CLI for the FIRST EPSS (Exploit Prediction Scoring System) API with advanced caching support.

Features

  • Fast & Typed: Full type hints and optimized performance
  • Advanced Caching: Redis, Database, and File-based caching
  • Configurable: YAML/TOML configuration files + environment variables
  • Statistics: Built-in cache performance monitoring
  • CLI Tools: Comprehensive command-line interface

Installation

pip install epss-client

# Optional: Install with caching support
pip install epss-client[cache-redis]     # Redis backend
pip install epss-client[cache-db]        # Database backend  
pip install epss-client[cache-full]      # All cache backends
pip install epss-client[config]          # Configuration file support

Quick start

Basic Usage (No Caching)

from epss_client import EpssClient

client = EpssClient()

# Single CVE
resp = client.get("CVE-2022-27225")
print(resp["data"][0])

# Batch CVEs
resp = client.batch(["CVE-2022-27225","CVE-2022-27223","CVE-2022-27218"]) 

# Time series (30 days)
resp = client.get("CVE-2022-25204", scope="time-series")

# Top N by EPSS
resp = client.top(limit=100)

# Filters and thresholds
resp = client.query(epss_gt=0.95)
resp = client.query(percentile_gt=0.95)

# Historic by date
resp = client.get("CVE-2022-26332", date="2022-03-05")

With Caching (New in v2.0!)

from epss_client import EpssClient, EpssClientConfig, CacheConfig

# Configure file-based caching
cache_config = CacheConfig(
    enabled=True,
    backend="file",  # or "redis", "database"
    ttl=3600        # 1 hour cache
)

client_config = EpssClientConfig(cache_config=cache_config)
client = EpssClient(config=client_config)

# First call hits the API
resp1 = client.get("CVE-2022-27225")  # ~200ms

# Second call hits the cache  
resp2 = client.get("CVE-2022-27225")  # ~2ms - 100x faster!

# View cache statistics
stats = client.get_cache_stats()
print(f"Cache hit rate: {stats['hit_rate']:.1%}")

# Clear cache when needed
client.clear_cache()

CLI Usage

Basic Commands

# Single CVE
epss get CVE-2022-27225

# Multiple CVEs
epss batch CVE-2022-27225 CVE-2022-27223 CVE-2022-27218

# Top CVEs by EPSS score
epss top --limit 100

# Generic queries with filters
epss query --limit 100 --epss-gt 0.95
epss query --percentile-gt 0.95 --date 2022-03-05

# Time series data
epss get CVE-2022-25204 --scope time-series

# Output formats
epss query --limit 5 --format json
epss query --limit 5 --format csv > data.csv

Cache Commands (New in v2.0!)

# Use caching with CLI options
epss get CVE-2022-27225 --cache-backend file --cache-ttl 3600

# Use configuration file
epss get CVE-2022-27225 --cache-config ~/.epss/config.yaml

# Disable cache for a single request
epss query --limit 100 --no-cache

# Cache management
epss cache stats                    # Show cache statistics
epss cache clear                    # Clear all cached data
epss cache config                   # Show current cache configuration

Caching System

EPSS Client v2.0 introduces a powerful, configurable caching system that can significantly improve performance for repeated queries.

Cache Backends

File Cache (Default)

from epss_client import CacheConfig

config = CacheConfig(
    enabled=True,
    backend="file",
    ttl=3600,  # 1 hour
)
config.file.directory = "~/.cache/epss"
config.file.max_size_mb = 100
config.file.compression = True

Redis Cache

config = CacheConfig(
    enabled=True,
    backend="redis",
    ttl=3600,
)
config.redis.host = "localhost"
config.redis.port = 6379
config.redis.db = 0

Database Cache

config = CacheConfig(
    enabled=True,
    backend="database",
    ttl=3600,
)
# SQLite (default)
config.database.url = "sqlite:///~/.cache/epss/cache.db"
# Or PostgreSQL
# config.database.url = "postgresql://user:pass@localhost/epss"

Configuration Files

Create ~/.epss/config.yaml:

cache:
  enabled: true
  backend: file  # or redis, database
  ttl: 3600
  
  file:
    directory: ~/.cache/epss
    max_size_mb: 100
    compression: true
    
  redis:
    host: localhost
    port: 6379
    db: 0
    
  database:
    url: sqlite:///~/.cache/epss/cache.db
    table_name: epss_cache

Load automatically:

from epss_client import CacheConfig, EpssClient, EpssClientConfig

# Loads from ~/.epss/config.yaml, ./epss.yaml, or env vars
cache_config = CacheConfig.load()
client_config = EpssClientConfig(cache_config=cache_config)
client = EpssClient(config=client_config)

Environment Variables

export EPSS_CACHE_ENABLED=true
export EPSS_CACHE_BACKEND=redis
export EPSS_CACHE_TTL=3600
export EPSS_CACHE_REDIS_HOST=localhost
export EPSS_CACHE_REDIS_PORT=6379

Cache Statistics

client = EpssClient(config=client_config)

# Make some cached requests
client.get("CVE-2022-27225")
client.get("CVE-2022-27225")  # Cache hit

# View statistics
stats = client.get_cache_stats()
print(f"Hit rate: {stats['hit_rate']:.1%}")
print(f"Total hits: {stats['hits']}")
print(f"Total misses: {stats['misses']}")
print(f"Cache backend: {stats['backend']}")

Per-Request Cache Control

# Disable cache for specific request
client.get("CVE-2022-27225", use_cache=False)

# Custom TTL for specific request
client.get("CVE-2022-27225", cache_ttl=7200)  # 2 hours

# Same for CLI
epss get CVE-2022-27225 --no-cache
epss get CVE-2022-27225 --cache-ttl 7200

API Coverage

This client wraps https://api.first.org/data/v1/epss with complete support for:

  • Single & Batch Queries: Individual CVEs or bulk operations
  • Time Series Data: Historical EPSS scores over time
  • Filtering & Sorting: By date, score thresholds, custom ordering
  • Pagination: Efficient handling of large datasets
  • Output Formats: JSON and CSV export
  • Caching: Intelligent caching with multiple backend options

Supported Parameters

  • cves: Single CVE or list of CVEs
  • date: Specific date (YYYY-MM-DD format)
  • scope: Use "time-series" for historical data
  • order: Sort results (e.g., "!epss" for descending EPSS score)
  • epss_gt: Filter by EPSS score greater than threshold
  • percentile_gt: Filter by percentile greater than threshold
  • limit & offset: Pagination controls
  • envelope & pretty: Response formatting options

See the official EPSS API documentation: https://api.first.org/epss

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

epss_client-2.0.0.tar.gz (22.8 kB view details)

Uploaded Source

Built Distribution

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

epss_client-2.0.0-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file epss_client-2.0.0.tar.gz.

File metadata

  • Download URL: epss_client-2.0.0.tar.gz
  • Upload date:
  • Size: 22.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.1

File hashes

Hashes for epss_client-2.0.0.tar.gz
Algorithm Hash digest
SHA256 5755027e73f4378de28fadf58a713a74ccab57828348271c130b1b44a6a349fa
MD5 31133862cff6d91c522d7aca0c93463c
BLAKE2b-256 c627126f8e37be2c7f77d577b38bf9b6b99f10be9152e78d627b94f0c73b7626

See more details on using hashes here.

File details

Details for the file epss_client-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: epss_client-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 19.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.1

File hashes

Hashes for epss_client-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0d31dfff22e683969fbe3da692c6d8e3da8c438ef1115ced0f43871e8c4d2722
MD5 36b42a09a50094462eac83f47e584e8e
BLAKE2b-256 b74208b5e5f7376357ea42a62c88ed82ff69ba86ccd9ec31c5b963d68267f651

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