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 scriptspydantic_cwe/: Main package directorymodels: Pydantic models for CWE data__init__.py: Package initialization and exportsloader.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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydantic_cwe-0.0.4.tar.gz.
File metadata
- Download URL: pydantic_cwe-0.0.4.tar.gz
- Upload date:
- Size: 13.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
97e2cc0a06020bbaf4daa1890ff5a65da46e2ddaaafe6fa185917718a55f9820
|
|
| MD5 |
6548774561818f313b1a842320f7a6c4
|
|
| BLAKE2b-256 |
1bb456dccf3c71959edc32ee8ed3f5a79d66ccf5ef6a52b151f9f987ad178463
|
File details
Details for the file pydantic_cwe-0.0.4-py3-none-any.whl.
File metadata
- Download URL: pydantic_cwe-0.0.4-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
835b43571e9cfdd5e1fbc68ed03a67e93c57216ef892bef51b392367daa674a3
|
|
| MD5 |
3a76d13172b58252a9f5962042398061
|
|
| BLAKE2b-256 |
87be38aa15f40eed19773d7361fff7c54fbe014f677e4522a55f6a715a0502ae
|