Structured object comparison and evaluation library
Project description
stickler-lib
A Python library for structured object comparison and evaluation with configurable comparison strategies and detailed metrics.
Installation
Requirements
- Python 3.12+
- conda (recommended)
Quick Install
# Create conda environment
conda create -n stickler python=3.12 -y
conda activate stickler
# Install the library
pip install -e .
Development Install
# Install with testing dependencies
pip install -e ".[dev]"
Quick Test
Run the example to verify installation:
python examples/scripts/quick_start.py
Run tests:
pytest tests/
Basic Usage
Static Model Definition
from stickler import StructuredModel, ComparableField, StructuredModelEvaluator
from stickler.comparators.levenshtein import LevenshteinComparator
# Define your data structure
class Invoice(StructuredModel):
invoice_number: str = ComparableField(
comparator=LevenshteinComparator(),
threshold=0.9
)
total: float = ComparableField(threshold=0.95)
# Compare objects
evaluator = StructuredModelEvaluator()
result = evaluator.evaluate(ground_truth, prediction)
print(f"Overall Score: {result['overall']['anls_score']:.3f}")
Dynamic Model Creation (New!)
Create models from JSON configuration for maximum flexibility:
from stickler.structured_object_evaluator.models.structured_model import StructuredModel
# Define model configuration
config = {
"model_name": "Product",
"match_threshold": 0.8,
"fields": {
"name": {
"type": "str",
"comparator": "LevenshteinComparator",
"threshold": 0.8,
"weight": 2.0
},
"price": {
"type": "float",
"comparator": "NumericComparator",
"default": 0.0
}
}
}
# Create dynamic model class
Product = StructuredModel.model_from_json(config)
# Use like any Pydantic model
product1 = Product(name="Widget", price=29.99)
product2 = Product(name="Gadget", price=29.99)
# Full comparison capabilities
result = product1.compare_with(product2)
print(f"Similarity: {result['overall_score']:.2f}")
Complete JSON-to-Evaluation Workflow (New!)
For maximum flexibility, load both configuration AND data from JSON:
# Load model config from JSON
with open('model_config.json') as f:
config = json.load(f)
# Load test data from JSON
with open('test_data.json') as f:
data = json.load(f)
# Create model and instances from JSON
Model = StructuredModel.model_from_json(config)
ground_truth = Model(**data['ground_truth'])
prediction = Model(**data['prediction'])
# Evaluate - no Python object construction needed!
result = ground_truth.compare_with(prediction)
Benefits of JSON-Driven Approach:
- Zero Python object construction required
- Configuration-driven model creation
- A/B testing different field configurations
- Runtime model generation from external schemas
- Production-ready JSON-based evaluation pipeline
- Full Pydantic compatibility with comparison capabilities
See examples/scripts/json_to_evaluation_demo.py for a complete working example and docs/StructuredModel_Dynamic_Creation.md for comprehensive documentation.
Examples
Check out the examples/ directory for more detailed usage examples and notebooks.
License
© 2025 Amazon Web Services, Inc. or its affiliates. All Rights Reserved.
Project details
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 stickler_eval-0.1.0.tar.gz.
File metadata
- Download URL: stickler_eval-0.1.0.tar.gz
- Upload date:
- Size: 100.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee05a94da1e375bfacf21b4a12bf3cfe0704ed669f72c92e34e5323be5ca0d29
|
|
| MD5 |
86de12810e11f6f4acff010844234b14
|
|
| BLAKE2b-256 |
cdc3dc75fb7523c37d18dbe25623c1e41f34784762e5b1c7714fab4109f81d05
|
File details
Details for the file stickler_eval-0.1.0-py3-none-any.whl.
File metadata
- Download URL: stickler_eval-0.1.0-py3-none-any.whl
- Upload date:
- Size: 125.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e125f950d26a6e651a32bfaa23c0eb0134884bce322241ec02f1b9f0d1812cb8
|
|
| MD5 |
e513c93e7c818f65b835123b1d4be0ae
|
|
| BLAKE2b-256 |
e905838569e613850c6b5b8c7dfdef320076eb7b58b64f6d67bbe386080c5054
|