Registry / data / pysigma

pysigma

JSON →
library1.3.3pypypi✓ verified 82d ago

pySigma is a Python library for processing and converting Sigma rules, a generic and open signature format that allows security analysts to describe relevant log events in a structured way. It serves as the core engine for Sigma rule management and transformation into various SIEM or EDR query languages. The current version is 1.3.2, with minor releases and bug fixes occurring frequently.

pip install pysigma
INSTALL
IMPORT
SIG · PYSIGMA
P
pysigma
datapythonv1.3.3
Install
3.1s avg
Import
Disk
27MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.3.3 · 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.940 runs
installs and imports cleanly · install 0.0s · import 0.000s · 28.6MB
glibc
py 3.103.940 runs
installs and imports cleanly · install 3.1s · import 0.000s · 30MB
27MB installed
● package 27MB
Code
Verified usage

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

PySigmaCollection
import sigma
from sigma import PySigmaCollection

This quickstart demonstrates how to load Sigma rules from a local directory, initialize a generic Sigma detection backend, and convert the rules into a textual representation suitable for a SIEM/EDR system. To convert to specific SIEM formats (e.g., Splunk, Elasticsearch), you need to install the corresponding `pysigma-plugin-<backend>` package and import the specific backend class.

import os from pysigma import PySigmaCollection from pysigma.backends.sigma import SigmaDetectionsBackend # Create a dummy Sigma rule file for demonstration rule_content = """ title: Detect PowerShell Encoded Command id: 03f57279-7928-4e89-a5e2-6320573e6a4b status: stable description: Detects PowerShell usage with encoded commands, often used in malicious activity. logsource: category: process_creation product: windows detection: selection: Image|endswith: - '\\powershell.exe' - '\\pwsh.exe' CommandLine|contains: - '-EncodedCommand' - '-eNcoDedCOmmaNd' condition: selection fields: - CommandLine - ParentCommandLine - Image tags: - attack.execution - attack.t1059.001 """ # Save the rule to a temporary directory if not os.path.exists('sigma_rules'): os.makedirs('sigma_rules') with open('sigma_rules/powershell_encoded_command.yml', 'w') as f: f.write(rule_content) # 1. Load Sigma rules from a directory collection = PySigmaCollection.from_directory('sigma_rules') print(f"Loaded {len(collection.rules)} Sigma rule(s).") # 2. Instantiate a backend (e.g., generic Sigma detection backend) # For Splunk, use: from pysigma.backends.splunk import SplunkBackend; backend = SplunkBackend() backend = SigmaDetectionsBackend() # 3. Process the collection using the backend # This generates a list of Backend_Rule objects detection_rules = backend.convert(collection) # 4. Print the converted query for each rule for rule in detection_rules: print(f"\nRule ID: {rule.id}") print(f"Query: {rule.text}") # Clean up the dummy rule file and directory os.remove('sigma_rules/powershell_encoded_command.yml') os.rmdir('sigma_rules')
Debug
Known issues
breakingpySigma v1.0.0 introduced significant breaking changes, including a redesigned API, new package structure, and changes to pipeline configuration. Key changes include `SigmaCollection` being replaced by `PySigmaCollection` for loading, movement of `SigmaRule` class, and a new structure for `Rule` objects.
fix
Review the official 'Breaking Changes' documentation for pySigma v1.0.0 on GitHub. Update import paths and API calls to align with the new structure. Specifically, use `from pysigma import PySigmaCollection` and refer to updated backend initialization patterns.
affects: >=1.0.0
breakingA security vulnerability was identified in v1.3.0 related to custom template variables. Untrusted processing pipelines utilizing the template vars feature could lead to unintended arbitrary code execution. Users should be aware that pipelines can imply execution of arbitrary code.
fix
Upgrade to pySigma v1.3.0 or later. Exercise extreme caution when using custom template variables and processing pipelines from untrusted sources, as they may contain malicious code. Only use pipelines from trusted origins.
affects: <1.3.0
gotchaPrior to v1.3.2, MITRE data loading in tag validators was not deferred. This could cause timeouts or errors when pySigma was used in offline environments or without proper internet access for MITRE ATT&CK data validation.
fix
Upgrade to pySigma v1.3.2 or later to benefit from deferred MITRE data loading, which resolves offline environment issues. If unable to upgrade, ensure internet connectivity for initial tag validation or disable MITRE tag validation if not critical.
affects: <1.3.2
gotchaAs of v1.0.1, pySigma uses PyPI dependency information for plugin compatibility checks. Custom or locally developed plugins might require explicit `pysigma_compatibility` entries in their `setup.py` or equivalent to ensure they are recognized as compatible.
fix
For custom plugins, ensure their packaging metadata explicitly declares compatibility with `pysigma` using `pysigma_compatibility` to avoid unexpected compatibility errors when `pysigma` performs its checks. Consult plugin development guidelines for details.
affects: >=1.0.1
Upgrade
Version history
1.3.3latest on PyPI · released Apr 21, 2026
Audit
Dependencies
pyparsingrequiredRequired for parsing Sigma rule syntax.
PyYAMLrequiredRequired for loading YAML-based Sigma rules and configurations.
pysigma-clioptionalProvides command-line interface, often used with pysigma for rule validation and conversion. Not a direct library dependency but common complement.
pysigma-plugin-<backend>optionalSpecific backend plugins (e.g., pysigma-plugin-splunk, pysigma-plugin-elasticsearch) are required to convert Sigma rules to target SIEM/EDR query languages. These are installed separately or via extras.
Agent activity
12 hits · last 30 days
node
10
Resources
pysigma — pip install pysigma · libregistry