safety-schemas
safety-schemas (version 0.0.18) provides Pydantic models and schemas used by the Safety CLI tool for defining structures like vulnerability database files, policy files, and JSON output formats. It serves as a foundational library for standardizing data structures within the Safety ecosystem. The library is actively maintained with a regular release cadence, often aligned with updates to the main Safety CLI.
Warnings
- gotcha Older versions of `safety-schemas` (e.g., 0.0.1) had strict upper version pins for `packaging` and `pydantic` that could lead to dependency conflicts, especially with newer Python environments (e.g., Python 3.8+ running Pydantic 2.x). This resulted in `safety` CLI being broken on affected Python versions.
- gotcha The `safety-schemas` library is primarily an internal dependency of the `safety` CLI tool. While its Pydantic models are importable, it lacks extensive standalone documentation for external usage. Direct programmatic use might require inspecting the `safety` CLI source code for usage patterns.
Install
-
pip install safety-schemas
Imports
- ConfigModel
from safety_schemas.models import ConfigModel
- VulnerabilitySeverityLabels
from safety_schemas.models import VulnerabilitySeverityLabels
- Stage
from safety_schemas.models import Stage
- Ecosystem
from safety_schemas.models import Ecosystem
Quickstart
from safety_schemas.models import VulnerabilitySeverityLabels
# Example of using a Pydantic model from safety-schemas
# This model defines the structure for vulnerability severity labels.
try:
# Instantiate a model instance with valid data
severity_labels = VulnerabilitySeverityLabels(
critical='Critical',
high='High',
medium='Medium',
low='Low',
unknown='Unknown'
)
print(f"Successfully created severity labels: {severity_labels.model_dump_json(indent=2)}")
# Accessing fields
print(f"High severity label: {severity_labels.high}")
# Attempting to create an invalid instance (Pydantic will raise ValidationError)
# Note: Pydantic models are strict by default on extra fields unless configured otherwise
# For demonstration, let's assume valid input for required fields.
except Exception as e:
print(f"Error creating severity labels: {e}")