Registry / serialization / safety-schemas

safety-schemas

JSON →
library0.0.20pypypi✓ verified 24d ago

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.

pip install safety-schemas
INSTALL
IMPORT
SIG · SAFETY-SCHEMAS
S
safety-schemas
serializationpythonv0.0.20
Install
3.7s avg
Import
766ms
Disk
29MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.0.20 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.806s · 30.6MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.7s · import 0.726s · 30MB
29MB installed
● package 29MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

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

This quickstart demonstrates how to import and instantiate a Pydantic model, `VulnerabilitySeverityLabels`, from the `safety_schemas.models` module. It shows basic data assignment, access to model fields, and how Pydantic's validation ensures data integrity upon instantiation.

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}")
Debug
Known issues
gotchaOlder 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.
fix
Ensure you are using the latest version of `safety-schemas` (0.0.18 or newer) as dependency pins are often relaxed in later releases. If conflicts persist, explicitly pin `packaging` and `pydantic` to versions compatible with your `safety-schemas` version, or consider using a dedicated virtual environment.
affects: 0.0.1 to potentially other early 0.x.x versions
gotchaThe `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.
fix
Refer to the `safety` CLI's GitHub repository (`pyupio/safety`) to understand how `safety-schemas` models are consumed and integrated within the broader Safety ecosystem. For general Pydantic usage, consult the Pydantic documentation.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'safety_schemas'
The `safety-schemas` library has not been installed in your Python environment or is not accessible on the Python path.
fix
pip install safety-schemas
ImportError: cannot import name 'Vulnerability' from 'safety_schemas'
Pydantic models like 'Vulnerability' are located within the `safety_schemas.models` submodule, not directly under the top-level `safety_schemas` package.
fix
from safety_schemas.models import Vulnerability
pydantic.ValidationError
The data provided to instantiate a `safety-schemas` Pydantic model does not conform to its defined schema, leading to validation failure.
fix
from safety_schemas.models import Vulnerability

# Ensure all required fields are present and correctly typed
valid_data = {
    "package_name": "example-package",
    "vulnerability_id": "GHSA-xxxx-xxxx-xxxx",
    "analyzed_version": "1.0.0",
    "vulnerable_version_range": "<1.0.0",
    "published_date": "2023-01-01T00:00:00Z",
    "advisory": "A test advisory description."
}
vulnerability_instance = Vulnerability(**valid_data)
Upgrade
Version history
0.0.20latest on PyPI · released Aug 20, 2026
Audit
Dependencies
pydanticrequiredProvides the base models for defining schemas.
Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
1
Resources
safety-schemas — pip install safety-schemas · libregistry