A robust, secure, and maintainable ONIX 3.x Python library using xsdata.
Project description
pyonix-core
A high-performance, type-safe, and secure Python library for processing ONIX 3.0 XML feeds. Built on top of xsdata and lxml, pyonix-core provides a robust foundation for bibliographic data exchange in the publishing industry.
Overview
ONIX for Books is the international standard for representing and communicating book industry product information in electronic form. pyonix-core simplifies the complexity of the ONIX 3.0 standard by providing:
- Strict Type Safety: Fully typed Python dataclasses generated directly from EDItEUR's official XSD schemas.
- Memory Efficiency: Iterative, streaming parsing capabilities designed to handle multi-gigabyte ONIX files with minimal memory footprint.
- Security First: Hardened XML parsing configuration to prevent XXE (XML External Entity) attacks and other common XML vulnerabilities.
- Developer Friendly: A high-level "Facade" pattern to abstract away the deeply nested structure of raw ONIX messages, providing simple access to common fields like ISBNs, titles, and prices.
Installation
Requires Python 3.11 or higher.
pip install .
Quick Start
Parsing an ONIX File
The core entry point is parse_onix_stream, which yields product records one by one. This allows you to process massive files without loading the entire document into memory.
from pyonix_core.parsing.parser import parse_onix_stream
from pyonix_core.facade.product import ProductFacade
file_path = "path/to/onix_feed.xml"
# parse_onix_stream automatically detects Reference vs Short tags
for product in parse_onix_stream(file_path):
# Wrap the raw data model in a Facade for easier access
facade = ProductFacade(product)
print(f"Title: {facade.title}")
print(f"ISBN-13: {facade.isbn13}")
print(f"Price: {facade.price_amount} {facade.price_currency}")
print("-" * 20)
Working with the Facade
The ProductFacade simplifies data extraction. Instead of navigating complex nested objects, you can access properties directly.
# Example of accessing data via Facade
print(f"Record Reference: {facade.record_reference}")
print(f"Contributors: {', '.join(facade.contributors)}")
Architecture
Data Models
The data models in pyonix_core.models are auto-generated using xsdata from the official ONIX 3.0 schemas. This ensures 100% compliance with the standard and provides excellent IDE support (autocompletion, type checking).
Security
XML parsing is handled by lxml with strict security settings:
resolve_entities=False: Prevents XXE attacks.no_network=True: Blocks remote resource fetching.load_dtd=False: Disables DTD processing.
Development
Running Tests
python -m unittest discover tests
Regenerating Models
If the schemas change, you can regenerate the data models:
python scripts/generate_models.py
License
This project is licensed under the MIT License.
Note: This project is currently in active development.
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 Distributions
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 pyonix_core-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pyonix_core-0.1.0-py3-none-any.whl
- Upload date:
- Size: 2.1 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
70060d89b3ccac170147d1456241be04dbbc8830a04e5e8a3e25a6597b9dd13c
|
|
| MD5 |
7f986ccc8bb2b48b0a165df89d058a49
|
|
| BLAKE2b-256 |
fe2a6c21ff8b85844d3d2a944c2e24b9c03496fdcc8a360f75b8ea95f1673a1c
|