Complex Object Metric - A library for measuring complexity of Python objects
Project description
Cobjectric
Complex Object Metric - A Python library for computing metrics on complex objects (JSON, dictionaries, lists, etc.).
📖 Description
Cobjectric is a library designed to help developers calculate metrics on complex objects such as JSON, dictionaries, and arrays. It was originally created for Machine Learning projects where comparing and evaluating generated JSON structures against ground truth data was a repetitive manual task.
🚀 Getting Started
For Users
pip install cobjectric
For Development
Prerequisites
- Python 3.13.9 or higher
- uv - Fast Python package installer
- Install dependencies with uv:
uv sync --dev
- Install pre-commit hooks:
uv run pre-commit install --hook-type pre-push
🛠️ Development
Available Commands
The project uses invoke for task management.
To see all available commands:
uv run inv --list
# or shorter:
uv run inv -l
To get help on a specific command:
uv run inv --help <command>
# Example:
uv run inv --help precommit
📚 Usage
Quick Example
Cobjectric allows you to define typed models and compute fill rate metrics to measure data completeness:
from cobjectric import BaseModel, Spec
class Person(BaseModel):
name: str = Spec(fill_rate_func=lambda x: len(x) / 100)
age: int
email: str
# Create from dictionary
person = Person.from_dict({
"name": "John Doe",
"age": 30,
"email": "john.doe@example.com",
})
# Compute fill rate (scoring)
result = person.compute_fill_rate()
print(result.fields.name.value) # 0.08 (len("John Doe") = 8, 8/100)
print(result.fields.age.value) # 1.0 (present)
print(result.fields.email.value) # 1.0 (present)
print(result.mean()) # 0.693... (average fill rate)
Fill rate measures how "complete" each field is (0.0 = missing, 1.0 = present). You can define custom fill rate functions or use the default (0.0 for missing, 1.0 for present).
See the documentation for more details on nested models, list fields, normalizers, and advanced features.
Features
- Fill Rate Scoring: Compute completeness metrics (fill rate) for all fields with statistical aggregation
- Typed Models: Define models with type annotations and automatic validation
- Nested Models: Support for nested model structures with recursive fill rate computation
- Field Normalizers: Transform field values before validation
- Flexible Types: Support for optional fields, union types, typed dicts, and lists
For complete feature list and details, see the documentation.
Documentation
For more information, see the documentation:
- Quick Start - Get started in 5 minutes
- BaseModel and Fields - Detailed guide and API reference
📝 License
This project is licensed under the MIT License - see the LICENSE file for details.
Citing Cobjectric
If you use Cobjectric in your research or projects, please consider citing it:
@software{cobjectric2025,
author = {Nigiva},
title = {Cobjectric: A Library for Computing Metrics on Complex Objects},
year = {2025},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/nigiva/cobjectric}},
version = {1.1.0}
}
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 cobjectric-1.1.0.tar.gz.
File metadata
- Download URL: cobjectric-1.1.0.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2dd941f46685aa69de9e767105787f22e7511e44209f96e285fa9253abe5bfbb
|
|
| MD5 |
3e27126b822da73349b3614193e7c95f
|
|
| BLAKE2b-256 |
7d30a05c764816c497788a937bcb956743f4a9e282d67b8b609d51c473b5776f
|
Provenance
The following attestation bundles were made for cobjectric-1.1.0.tar.gz:
Publisher:
release.yml on nigiva/cobjectric
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cobjectric-1.1.0.tar.gz -
Subject digest:
2dd941f46685aa69de9e767105787f22e7511e44209f96e285fa9253abe5bfbb - Sigstore transparency entry: 785771358
- Sigstore integration time:
-
Permalink:
nigiva/cobjectric@6c6a8ff962b27a27548d54321bf24ce71f47e028 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/nigiva
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@6c6a8ff962b27a27548d54321bf24ce71f47e028 -
Trigger Event:
pull_request
-
Statement type:
File details
Details for the file cobjectric-1.1.0-py3-none-any.whl.
File metadata
- Download URL: cobjectric-1.1.0-py3-none-any.whl
- Upload date:
- Size: 15.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e6782e961401c316bc2eccbdbd5e08ccdb34968e1bdb8ce72e76dc17331f3b1
|
|
| MD5 |
238dd368205733e5f26aeee11bb4b469
|
|
| BLAKE2b-256 |
0dea6d51b40a14877c2c0c4a59548edbf17cfade5fa01846807bb638a19b6242
|
Provenance
The following attestation bundles were made for cobjectric-1.1.0-py3-none-any.whl:
Publisher:
release.yml on nigiva/cobjectric
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cobjectric-1.1.0-py3-none-any.whl -
Subject digest:
2e6782e961401c316bc2eccbdbd5e08ccdb34968e1bdb8ce72e76dc17331f3b1 - Sigstore transparency entry: 785771395
- Sigstore integration time:
-
Permalink:
nigiva/cobjectric@6c6a8ff962b27a27548d54321bf24ce71f47e028 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/nigiva
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@6c6a8ff962b27a27548d54321bf24ce71f47e028 -
Trigger Event:
pull_request
-
Statement type: