A Python library for parsing and manipulating YARA rules using Abstract Syntax Trees
Project description
yaraast
Parse, analyze, and transform YARA rules with a Python AST toolkit
Overview
yaraast is a Python library for parsing and manipulating YARA-family rules using Abstract Syntax Trees (AST). It supports classic YARA, YARA-L, and YARA-X workflows with automatic dialect detection and CLI tooling.
Key Features
| Feature | Description |
|---|---|
| Multi-dialect Parsing | Parse YARA, YARA-L, and YARA-X from files or strings |
| Automatic Dialect Detection | Unified parser auto-detects rule dialects |
| AST Tooling | Build, transform, diff, and serialize ASTs |
| Formatting & Validation | CLI commands for parse/format/validate workflows |
| Streaming Support | Parse very large files with streaming mode |
| Ecosystem Integrations | Optional LSP and libyara-related capabilities |
Supported Rule Ecosystem
Dialects YARA, YARA-L, YARA-X
Parsers Standard parser, unified parser, streaming parser
Outputs YARA, JSON, YAML, AST tree views
Tooling CLI, visitors, builders, serialization, semantic checks
Installation
From PyPI (Recommended)
pip install yaraast
From Source
git clone https://github.com/mriverolopez/yaraast.git
cd yaraast
python3 -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -e .
Quick Start
from yaraast.unified_parser import UnifiedParser
yara_code = """
rule example {
strings:
$a = "malware" nocase
condition:
$a
}
"""
ast = UnifiedParser.parse_string(yara_code)
print(ast.rules[0].name)
Usage
Command Line Interface
# Parse and print normalized YARA
yaraast parse rules.yar
# Parse to JSON
yaraast parse rules.yar --format json
# Parse with explicit dialect
yaraast parse rules.yar --dialect yara-x
# Validate file (syntax + parse checks)
yaraast validate rules.yar
# Format file in-place (AST-based formatter)
yaraast fmt rules.yar
# Check formatting without modifying file
yaraast fmt rules.yar --check
Core CLI Commands
| Command | Description |
|---|---|
parse |
Parse a rule file and output YARA/JSON/YAML/tree |
validate |
Validate rules and run validation subcommands |
fmt |
AST-based formatter (with --check and --diff) |
format |
Format input into a target output file |
validate-syntax |
Syntax-focused validation entrypoint |
lsp |
Launch Language Server Protocol features |
Python Library
Unified Parsing
from yaraast.unified_parser import UnifiedParser
from yaraast.dialects import YaraDialect
# Auto-detect dialect
ast = UnifiedParser.parse_file("rules.yar")
# Force specific dialect
ast = UnifiedParser.parse_file("rules.yar", dialect=YaraDialect.YARA)
Direct Parser + Visitor
from yaraast import Parser
from yaraast.visitor import BaseVisitor
class RuleCollector(BaseVisitor):
def __init__(self):
self.rules = []
def visit_rule(self, node):
self.rules.append(node.name)
super().visit_rule(node)
ast = Parser(open("rules.yar", encoding="utf-8").read()).parse()
collector = RuleCollector()
collector.visit(ast)
print(collector.rules)
Optional Dependencies
# LSP support
pip install yaraast[lsp]
# libyara integration
pip install yaraast[libyara]
# Performance tooling
pip install yaraast[performance]
# Visualization support
pip install yaraast[visualization]
# Everything
pip install yaraast[all]
Runtime Docs
- LSP runtime internals: docs/lsp-runtime.md
- LSP parity report: docs/lsp-parity-report.md
- Latest runtime benchmark artifact: docs/benchmarks/lsp-runtime-latest.json
Requirements
- Python 3.13+
- See pyproject.toml for full dependency and extras list
Contributing
Contributions are welcome. See CONTRIBUTING.md for setup, quality checks, and workflow guidelines.
- Fork the repository
- Create a branch (
git checkout -b feature/your-change) - Commit changes (
git commit -m "Add your change") - Push (
git push origin feature/your-change) - Open a Pull Request
License
This project is licensed under the MIT License - see LICENSE.
Author
- Marc Rivero (mriverolopez@gmail.com)
- Repository: github.com/mriverolopez/yaraast
Built for malware analysis and detection engineering workflows
Project details
Release history Release notifications | RSS feed
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 yaraast-1.0.1.tar.gz.
File metadata
- Download URL: yaraast-1.0.1.tar.gz
- Upload date:
- Size: 753.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e44d8c9a96303570599dc88152ae1292926a63e6406d05b257b5393a8fea9a6f
|
|
| MD5 |
191062e20d35c1370ed55bb0a12332d7
|
|
| BLAKE2b-256 |
56ef417b2d3ab0944efa0b5e79cf778dcda30a066b5600660d001762c3fc85e4
|
Provenance
The following attestation bundles were made for yaraast-1.0.1.tar.gz:
Publisher:
release.yml on seifreed/yaraast
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
yaraast-1.0.1.tar.gz -
Subject digest:
e44d8c9a96303570599dc88152ae1292926a63e6406d05b257b5393a8fea9a6f - Sigstore transparency entry: 1191489982
- Sigstore integration time:
-
Permalink:
seifreed/yaraast@02608553643fe671bef3bfec06a3a185ae74cfe4 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/seifreed
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@02608553643fe671bef3bfec06a3a185ae74cfe4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file yaraast-1.0.1-py3-none-any.whl.
File metadata
- Download URL: yaraast-1.0.1-py3-none-any.whl
- Upload date:
- Size: 600.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56079363ac4f830e60f799f9d29751e0e67b6b419fcab5bbadd8053f1ab14985
|
|
| MD5 |
ec299521e9ff3aab4174d7f4eec61340
|
|
| BLAKE2b-256 |
1edd5174cac9c522e08aa8e5cef541bd7e18fc20288aa63b871db6508a3060c7
|
Provenance
The following attestation bundles were made for yaraast-1.0.1-py3-none-any.whl:
Publisher:
release.yml on seifreed/yaraast
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
yaraast-1.0.1-py3-none-any.whl -
Subject digest:
56079363ac4f830e60f799f9d29751e0e67b6b419fcab5bbadd8053f1ab14985 - Sigstore transparency entry: 1191489984
- Sigstore integration time:
-
Permalink:
seifreed/yaraast@02608553643fe671bef3bfec06a3a185ae74cfe4 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/seifreed
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@02608553643fe671bef3bfec06a3a185ae74cfe4 -
Trigger Event:
push
-
Statement type: