Skip to main content

A Pythonic representation of CWE records using Pydantic models.

Project description

pydantic-cwe

pydantic-cwe provides a structured, object-oriented way to work with the Common Weakness Enumeration (CWE) database. By modeling CWE entries as Pydantic objects, this library enables developers and security researchers to programmatically access, validate, and manipulate CWE data with ease. Ideal for static analysis tools, vulnerability scanners, or custom security pipelines.

Installation

pip install pydantic-cwe

Usage

Loading a CWE catalog

from pydantic_cwe import Loader

# Create a loader instance
loader = Loader()

# Load the catalog
catalog = loader.load()

# Print some basic information about the catalog
print(f"Catalog Name: {catalog.name}")
print(f"Catalog Version: {catalog.version}")
print(f"Catalog Date: {catalog.date}")
print(f"Number of weaknesses: {len(catalog.weaknesses.weaknesses)}")

Working with weaknesses

from pydantic_cwe import Loader

loader = Loader()
catalog = loader.load()

# Get weaknesses ordered by ID
for weakness in catalog.get_ordered_weaknesses():
    if weakness.status == 'Deprecated':
        continue

    print(f"ID: {weakness.id}")
    print(f"Name: {weakness.name}")
    print(f"Abstraction: {weakness.abstraction}")
    print(f"Structure: {weakness.structure}")
    print(f"Status: {weakness.status}")
    print(f"Description: {weakness.description}")

Project Structure

The project follows a standard Python library structure:

  • examples/: Example scripts
  • pydantic_cwe/: Main package directory
    • models: Pydantic models for CWE data
    • __init__.py: Package initialization and exports
    • loader.py: XML loading and parsing functionality
  • tests/: Unit tests

Development

Setting up the development environment

# Clone the repository
git clone https://github.com/epicosy/pydantic-cwe.git
cd pydantic-cwe

# Create a virtual environment
python -m venv env
source env/bin/activate  # On Windows: env\Scripts\activate

# Install development dependencies
pip install -e ".[test]"

Running tests

pytest

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

pydantic_cwe-0.0.2.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

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

pydantic_cwe-0.0.2-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_cwe-0.0.2.tar.gz.

File metadata

  • Download URL: pydantic_cwe-0.0.2.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.7

File hashes

Hashes for pydantic_cwe-0.0.2.tar.gz
Algorithm Hash digest
SHA256 c197eb59424b871afb8f494621b14d18a0a2e8d179911ffd64f1c20520c7b63e
MD5 de7bec1262f1707757018439dc2e5a8d
BLAKE2b-256 bdf77102e801505de9b3177424e7e8863e05c6d71009707f7f2f698e0aa89adf

See more details on using hashes here.

File details

Details for the file pydantic_cwe-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: pydantic_cwe-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.7

File hashes

Hashes for pydantic_cwe-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 83d59d3abe1b14f7ed2ea38d05905a708c1603d69874947c10a3f2f7c702d492
MD5 762951f474873a0cfda1474be28dc2d4
BLAKE2b-256 e32fed7cc126d92d18fb7b3d2f0882d3181d055cdfc965f1663bfd46a9323cb3

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