A comprehensive Python SDK for interacting with the ICC Rule Engine API.
pip install icc-rule-engine-sdkfrom icc_rule_engine import ICCRuleEngineClient, Rule
# Initialize client
client = ICCRuleEngineClient(
base_url="https://your-api.onrender.com",
api_key="your-api-key"
)
# Check API health
health = client.health_check()
print(f"API Status: {health.status}")
# Create a rule
rule = Rule(
source="UCP600",
rule_id="TEST_RULE_001",
article="14",
title="Document Presentation Requirements",
text="Documents must be presented within 21 days after shipment date.",
condition={
"type": "date_range_check",
"left_path": "presentation_date",
"right_path": "shipment_date",
"max_days_difference": 21
},
expected_outcome={
"action": "validate",
"result": "compliant"
},
tags=["timing", "presentation"],
severity="high"
)
created_rule = client.create_rule(rule)
print(f"Created rule: {created_rule.rule_id}")
# Validate a document
document = {
"id": "LC_2024_001",
"document_type": "letter_of_credit",
"presentation_date": "2024-01-20",
"shipment_date": "2024-01-15",
"credit_amount": 100000
}
result = client.validate_document(
document=document,
ruleset={"source": "UCP600", "article": "14"}
)
print(f"Validation result: {result.ok}")
print(f"Score: {result.score}")
if result.violations:
for violation in result.violations:
print(f"Violation: {violation.message}")import asyncio
from icc_rule_engine import AsyncICCRuleEngineClient
async def main():
async with AsyncICCRuleEngineClient(
base_url="https://your-api.onrender.com",
api_key="your-api-key"
) as client:
result = await client.validate_document(
document=document,
ruleset={"source": "UCP600"}
)
print(f"Async validation result: {result.ok}")
asyncio.run(main())- Complete API Coverage: All ICC Rule Engine endpoints
- Type Safety: Full Pydantic model validation
- Async Support: Both sync and async clients
- Error Handling: Comprehensive exception hierarchy
- Retry Logic: Automatic retries with exponential backoff
- Rate Limiting: Built-in rate limit handling
- Authentication: API key authentication
- Timeouts: Configurable request timeouts
create_rule(rule)- Create a new ruleget_rule(rule_id)- Get rule by IDupdate_rule(rule_id, rule)- Update existing ruledelete_rule(rule_id)- Delete rulelist_rules(**filters)- List rules with filters
validate_document(document, ruleset)- Validate single documentvalidate_batch(documents, ruleset, parallel=True)- Validate multiple documents
health_check()- Check API healthget_metrics()- Get API metrics
Core rule model with all validation and metadata fields.
Complete validation result including score, violations, and applied rules.
ICCRuleEngineError- Base exceptionAPIError- API-related errorsAuthenticationError- Authentication failuresValidationError- Validation failuresNetworkError- Network-related errorsTimeoutError- Request timeoutsRateLimitError- Rate limit exceeded
ICC_RULE_ENGINE_BASE_URL=https://your-api.onrender.com
ICC_RULE_ENGINE_API_KEY=your-api-key
ICC_RULE_ENGINE_TIMEOUT=30.0
ICC_RULE_ENGINE_MAX_RETRIES=3client = ICCRuleEngineClient(
base_url="https://your-api.onrender.com",
api_key="your-api-key",
timeout=30.0, # Request timeout in seconds
max_retries=3, # Maximum retry attempts
retry_delay=1.0 # Base delay between retries
)from icc_rule_engine import ICCRuleEngineClient, APIError, AuthenticationError
try:
result = client.validate_document(document, ruleset)
except AuthenticationError:
print("Invalid API key")
except APIError as e:
print(f"API error: {e.message} (status: {e.status_code})")
except Exception as e:
print(f"Unexpected error: {e}")# Install development dependencies
pip install -e .[dev]
# Run tests
pytest
# Run tests with coverage
pytest --cov=icc_rule_engine --cov-report=html# Format code
black icc_rule_engine/
isort icc_rule_engine/
# Type checking
mypy icc_rule_engine/MIT License - see LICENSE file for details.
For support and bug reports, please visit: https://github.com/your-org/icc-rule-engine/issues