Skip to main content

Threat Modeling as Code (Python)

A declarative threat-modeling library for Python. Express your system as components, trust boundaries, and data flows, then analyze it with the STRIDE methodology to get actionable, version-controlled mitigations.

Features

  • Declarative Model, Component, Boundary, and DataFlow types
  • STRIDE threat classification: Spoofing, Tampering, Repudiation, Information Disclosure, Denial of Service, Elevation of Privilege
  • Trust-boundary-aware data flow analysis
  • Built-in, context-aware mitigation catalog
  • Zero runtime dependencies
  • Type hints included (py.typed)

Installation

pip install threat-modeling-py

Quick Start

from threat_modeling import Model, Component, Boundary

app = Model('payment-api')
app.add(Component('api', component_type='api', environment='k8s',
                  stores=['user-data'], exposed=True))
app.add(Boundary('internet', untrusted=True, trusts=['api']))

for threat in app.analyze():
    print(threat.kind, threat.target)
    for mitigation in threat.mitigations:
        print('  -', mitigation)

Development

cd implementations/security/threat-modeling/python
pip install -e ".[dev]"
pytest test_threat_modeling.py -v

Publishing to PyPI

cd implementations/security/threat-modeling/python
python -m build
python -m twine check dist/*
python -m twine upload dist/*

License

MIT License

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

threat_modeling_py-1.0.0.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

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

threat_modeling_py-1.0.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file threat_modeling_py-1.0.0.tar.gz.

File metadata

  • Download URL: threat_modeling_py-1.0.0.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.5

File hashes

Hashes for threat_modeling_py-1.0.0.tar.gz
Algorithm Hash digest
SHA256 a5f04305589d2734e41b8fda66677cc3fb9cf797306f939dfe74ffcc635a407b
MD5 2bc1b1633065cd3a408bb987b87ab980
BLAKE2b-256 9e49bf27cacf43be7a7436208c8c5b612b50555a39ab5ac458fbdfb51b5ec021

See more details on using hashes here.

File details

Details for the file threat_modeling_py-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for threat_modeling_py-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3b573f0219c5863ec98a8c8e7a101e546fa744138db588fe116307d3463c862a
MD5 802b23737a1eb2ab9216e4e13959c431
BLAKE2b-256 b1b4f53801a84374f628ccdd0f0da59be18ffa57c4e45ea9b14fbcbfd0b94061

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 files

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