yara-python is the official Python interface for YARA, a pattern matching tool used by security researchers to identify and classify malware. It provides bindings to the YARA C library, allowing Python applications to compile and apply YARA rules. The library is actively maintained, with new versions (currently 4.5.4) typically released in conjunction with updates to the underlying YARA engine.
pip install yara-pythonVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to compile a simple YARA rule from a string and then apply it to scan binary data. It shows how to access the matched rule's name, tags, and details about the matched strings, including their identifiers, offsets, and data.
Update code iterating over `match.strings`. Instead of direct tuple unpacking, access attributes like `s.identifier`, `s.instances[0].offset`, and `s.instances[0].matched_data` on the `yara.StringMatch` and `yara.StringMatchInstance` objects.
Before `pip install yara-python`, install YARA and its development packages (e.g., `libyara-dev`, `python3-dev`, `gcc` on Debian/Ubuntu, or `yara` via Homebrew on macOS).
Upgrade to `yara-python` version 4.4.0 or later to ensure memory stability when working with `StringMatchInstance` objects.
Use `yara.compile()` for human-readable rule files (.yara, .yar) or rule strings, and `yara.load()` only for binary pre-compiled rule files. Using `load()` on a text rule file will result in an error.
Install the package using `pip install yara-python`.
Ensure the YARA C library (e.g., `yara.dll` on Windows, `libyara.so` on Linux) is correctly installed and discoverable in your system's PATH, or specify its location using the `YARA_DLL_PATH` environment variable on Windows.
Install the YARA development package for your operating system (e.g., `sudo apt-get install libyara-dev` on Debian/Ubuntu, `brew install yara` on macOS, or build YARA from source).
Carefully review the YARA rule's syntax, ensuring it adheres to the YARA grammar and correcting any malformed expressions or keywords.
No dependency data recorded yet.