Skip to main content

CWE Tree

Python package for querying the Common Weakness Enumeration (CWE) hierarchy as a multi-rooted forest structure.

Quick Start

from cwe_tree import query

# Get a node
node = query.get_cwe("CWE-79")  # Both "79" and "CWE-79" works

# Navigate relationships
parents = query.get_parents("CWE-79")
children = query.get_children("CWE-79")

# Get metadata
metadata = query.get_metadata("CWE-79")

# Traverse forest
roots = query.get_root_nodes()
descendants = query.descendants(node)
ancenstors = query.ancenstors(node)

# Subnode Check
query.is_ancestor("CWE-74", "CWE-77")  
query.is_descendant("CWE-77", "CWE-74") 

# Visualize structure
query.show()                    # Display entire forest
query.show("CWE-79")          # Display subtree from specific node

Install

pip install cwe-tree

# With dev tools (linters, type checker, jupyter)
pip install -e ".[dev]"
# or
uv sync --dev

API

Core Methods

Method Purpose
node(cwe_id) Get node by ID
nodes(predicate=None) Iterate all nodes with optional filter
get_parents(cwe_id) Get parent nodes
get_children(cwe_id) Get child nodes
get_metadata(cwe_id) Get complete node metadata with relationships
get_layer(cwe_id) Get layer/depth information
get_root_nodes() Get all root nodes (no parents)
show(cwe_id=None) Visualize forest structure with ASCII tree

Traversal (inherited from AbcGraphQuerier)

Method Purpose
succ(node, predicate=None) Get successor nodes
prev(node, predicate=None) Get predecessor nodes
descendants(node, max_depth=None) BFS to find all descendants
ancestors(node, max_depth=None) BFS to find all ancestors
edges(predicate=None) Iterate all edges
first_node(predicate=None) Get first matching node

Data Model

  • Forest Structure: Multiple independent trees with different roots (CWEs with no parents)
  • Edge Type: "PARENT_OF" edges flow parent → child
  • Node Properties: id, name, abstract (Class/Base/Variant), layer (depth in hierarchies)

Documentation

Development

Code Quality

All code must pass (perfect score maintained):

make quality  # Run all checks

# Or individually:
uv run isort --check-only src/
uv run black --check src/
uv run mypy src/
uv run pylint src/

Format Code

make format

Run Tests

# Coming soon - comprehensive test suite

Architecture

See docs/design.md for:

  • Problem statement and system role
  • Core concepts (nodes, trees, forest structure)
  • Project structure
  • Data contracts
  • Typical scenarios and boundary cases

License

MIT


Metadata

Release files for cwe-tree 1.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cwe-tree 1.1.2
File Size Uploaded Provenance Actions
cwe_tree-1.1.2.tar.gz 151.2 kB Without provenance Details for cwe_tree-1.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cwe-tree 1.1.2
File Interpreter ABI Platform Actions
cwe_tree-1.1.2-py3-none-any.whl Python 3 none any Details for cwe_tree-1.1.2-py3-none-any.whl

Total release size: 180.3 kB

Release files / cwe_tree-1.1.2.tar.gz

Download URL cwe_tree-1.1.2.tar.gz
Size 151.2 kB
Tags Source
SHA-256 checksum
How to use checksums
5df9f93c5589df3b177e03da7ab46f671596fb8a2726d5d7408db779533d4902
BLAKE2b-256 checksum
How to use checksums
696c73a98eaea5d6e4c5327d400d717195eddebe83ca308b7c259cc197c11a3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.12

Release files / cwe_tree-1.1.2-py3-none-any.whl

Download URL cwe_tree-1.1.2-py3-none-any.whl
Size 29.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0e1f3f96c09cd0e53cada45dff9a1de9d855fd254adec902727b0de0af50514b
BLAKE2b-256 checksum
How to use checksums
6e830189a8fd814dfc38c361ef34cd850b3e99b69ed5215b7fc373bb095206dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.12

Security for cwe-tree 1.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page