Берёста для Python
Обёртка над Си-интерфейсом «Берёсты» через стандартный модуль ctypes: DOM, XPath 1.0, XML Schema с xs:key/xs:keyref, DTD, восемь кодировок. Зависимостей нет.
pip install beresta
import beresta
with beresta.parse("<shop><item code='A1'>Чай</item></shop>") as document:
item = document.root.first_child
print(item.get_attribute("code"), item.text)
Колесо из PyPI одно на все платформы и уже содержит библиотеку для Windows (x64, arm64), Linux (x64, arm64; glibc 2.35+) и macOS (универсальная: Intel и Apple Silicon) — компилятор не нужен. Сборка из исходников: make PYTHON=1 или cmake -DBERESTA_BUILD_PYTHON=ON в корне репозитория — бинарник окажется в beresta/_native/<os>-<arch>/.
Как получить скорость C++. Каждый шаг ручного обхода (first_child, next_sibling) — вызов через ctypes и новый объект-обёртка: миллион таких шагов измеряет скорость ctypes, а не парсера. Тяжёлую работу отдавайте ядру целиком:
from beresta import Schema, XPath
schema = Schema.from_file("export.xsd")
problems = schema.validate_file("export.xml") # поток без дерева, хоть гигабайты
prices = XPath("//item/@price").select_values(document) # строки без объектов-узлов
XPathкомпилируется один раз и вычисляется сколько угодно раз, в том числе из разных потоков: ctypes отпускает GIL на время вызова.- Потоковая проверка (
validate_file,validate_bytes) почти вдвое быстрее lxmliterparseсо схемой (93 против 49 МБ/с), а файл 135 МБ проверяется в 37 МБ собственной памяти процесса. - Дерево на 28 % компактнее, чем у lxml (86 против 119 МБ на каталоге 13 МБ).
- Защита от сущностных бомб и XXE включена в ядре: настраивать ничего не нужно.
- Строка и столбец нарушений в
schema.validate(document)— с флагомParseFlags.TRACK_LOCATIONSпри разборе.
Beresta for Python
A wrapper over the Beresta C interface through the standard ctypes module: DOM, XPath 1.0, XML Schema with xs:key/xs:keyref, DTD, eight encodings. No dependencies.
pip install beresta
The wheel from PyPI is one for all platforms and already contains the library for Windows (x64, arm64), Linux (x64, arm64; glibc 2.35+) and macOS (universal: Intel and Apple Silicon) — no compiler is needed. Building from source: make PYTHON=1 or cmake -DBERESTA_BUILD_PYTHON=ON in the repository root — the binary lands in beresta/_native/<os>-<arch>/.
How to get C++ speed. Every step of a manual walk (first_child, next_sibling) is a call through ctypes and a new wrapper object: a million such steps measure the speed of ctypes, not of the parser. Hand heavy work over to the core entirely:
from beresta import Schema, XPath
schema = Schema.from_file("export.xsd")
problems = schema.validate_file("export.xml") # a stream without a tree, even gigabytes
prices = XPath("//item/@price").select_values(document) # strings without node objects
- An
XPathis compiled once and evaluated any number of times, including from different threads: ctypes releases the GIL for the call time. - Streaming validation (
validate_file,validate_bytes) is almost twice as fast as lxmliterparsewith a schema (93 against 49 MB/s), and a 135 MB file is validated in 37 MB of the process's own memory. - The tree is 28 % more compact than lxml's (86 against 119 MB on a 13 MB catalog).
- The protection against entity bombs and XXE is on in the core: nothing needs to be configured.
- The line and column of violations in
schema.validate(document)come with theParseFlags.TRACK_LOCATIONSparse flag.
Metadata
Release files for beresta 2.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| beresta-2.2.0-py3-none-any.whl | Python 3 | none | any | Details for beresta-2.2.0-py3-none-any.whl |
Release files / beresta-2.2.0-py3-none-any.whl
| Download URL | beresta-2.2.0-py3-none-any.whl |
|---|---|
| Size | 5.0 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b511aeb7716d110b7cac776485afabdfc9c3c20ef137aff155858aab47e011be
|
|
BLAKE2b-256 checksum How to use checksums |
48b95f61763a3db9cfd0cd4ae055c204b2a88558145b9361fd5480edf2bfe509
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.15
|
Security for beresta 2.2.0
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.