A robust, secure Python reference parser for the CommerceTXT protocol.
Project description
CommerceTXT Python Reference Parser (v1.0.2)
A robust, secure, and production-ready Python parser for the CommerceTXT protocol. This library handles parsing, validation, fractal inheritance, and advanced security checks for commerce.txt files.
Key Features
- Fractal Inheritance: Support for resolving and merging nested directives across multiple files.
- Comprehensive Validation: Sequential Tier-based validation with a new
--validatereport flag. - AI-Ready Bridge: Enhanced support for directives like
BRAND_VOICE,SEMANTIC_LOGIC, andPROMOS. - Robust Test Suite: Includes Property-based testing (Hypothesis), Fuzz testing, and 95%+ code coverage.
- High-Performance Caching: Built-in LRU caching to skip redundant parsing for unchanged files.
- Async Support: Concurrent parsing for bulk file processing using AsyncCommerceTXTParser.
- AI Readiness Bridge: Native support for generating clean, low-token prompts for Large Language Models (LLMs).
- Enterprise-Grade Security: Blocks localhost, private IP ranges, and exotic IP notations (Octal, Hex, Integer).
Installation & Setup
Ensure you have Python 3.8+ installed.
Install the package directly from PyPI:
pip install commercetxt
CLI Usage
Validate files or generate AI-ready prompts instantly.
Comprehensive Validation Report:
python -m commercetxt.cli path/to/commerce.txt --validate
Basic Validation:
python -m commercetxt.cli path/to/commerce.txt
Generate AI Prompt:
python -m commercetxt.cli product.txt --prompt
Advanced Usage:
python -m commercetxt.cli commerce.txt --json --metrics --log-level DEBUG
Library Usage
- Basic Parsing & Validation:
from commercetxt import CommerceTXTParser, CommerceTXTValidator
parser = CommerceTXTParser()
result = parser.parse(content)
validator = CommerceTXTValidator(strict=False)
validator.validate(result)
- High-Speed Caching:
from commercetxt.cache import parse_cached
result = parse_cached(content)
- Bulk Async Parsing:
import asyncio
from commercetxt.async_parser import AsyncCommerceTXTParser
async def main():
async_parser = AsyncCommerceTXTParser()
results = await async_parser.parse_many([file1, file2])
asyncio.run(main())
Testing & Quality
CommerceTXT 1.0.2 maintains a 95% code coverage and utilizes a multi-layered testing strategy:
- Data-Driven: 150+ test vectors covering valid and malformed scenarios.
- Property-Based: Using
Hypothesisto ensure logical consistency. - Fuzzing: Stress-testing the parser against arbitrary random input.
- Security Audit: Automated checks for SSRF prevention and DoS mitigation.
Security Limits
- MAX_FILE_SIZE: 10 MB
- MAX_SECTIONS: 1000
- MAX_LINE_LENGTH: 100 KB
- MAX_NESTING: 100
- Blocked IPs: Any Reserved (Prevents SSRF)
Project Structure
- parser.py: Core parsing logic with optimized Regex compilation.
- validator.py: Business logic divided into compliance Tiers.
- security.py: Network security utilities (IP and URL validation).
- bridge.py: Token-efficient prompt generator for LLM integration.
- async_parser.py: Async engine for concurrent processing.
- cache.py: LRU caching implementation for performance.
- resolver.py: Locale resolution and fractal inheritance logic.
- metrics.py: Singleton for real-time performance tracking.
Running Tests
Requires pytest and pytest-asyncio.
pytest parsers/python/tests/
python -m pytest --cov=commercetxt --cov-report=html
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 commercetxt-1.0.2.tar.gz.
File metadata
- Download URL: commercetxt-1.0.2.tar.gz
- Upload date:
- Size: 39.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d01a8933452741cc9d899b84d60808a2a6277eef8aded5eeab6cd507e33e1ef
|
|
| MD5 |
3ce987b2388879dada7c170f1811b12e
|
|
| BLAKE2b-256 |
334c5c7fe31d4eaec489a251c979eb3f04ac956f09d5b336565019efc54ad6fc
|
File details
Details for the file commercetxt-1.0.2-py3-none-any.whl.
File metadata
- Download URL: commercetxt-1.0.2-py3-none-any.whl
- Upload date:
- Size: 22.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
edd3c91858771daa9173d2a7a5540c99b66930cbf2f6b867584630e671703e8e
|
|
| MD5 |
c04cb3c67777cc984ceb410783bf3ad1
|
|
| BLAKE2b-256 |
cb65cbe23e9a5da8c8ae9e7366b4d62fc08e0eafa9df4c0b7ac29e9e3a385f5d
|