Skip to main content

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.).

CI codecov PyPI version Python Version License Code style: black Ruff

📖 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
  1. Install dependencies with uv:
uv sync --dev
  1. 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:

📝 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

cobjectric-1.1.0.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cobjectric-1.1.0-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

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

Hashes for cobjectric-1.1.0.tar.gz
Algorithm Hash digest
SHA256 2dd941f46685aa69de9e767105787f22e7511e44209f96e285fa9253abe5bfbb
MD5 3e27126b822da73349b3614193e7c95f
BLAKE2b-256 7d30a05c764816c497788a937bcb956743f4a9e282d67b8b609d51c473b5776f

See more details on using hashes here.

Provenance

The following attestation bundles were made for cobjectric-1.1.0.tar.gz:

Publisher: release.yml on nigiva/cobjectric

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for cobjectric-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2e6782e961401c316bc2eccbdbd5e08ccdb34968e1bdb8ce72e76dc17331f3b1
MD5 238dd368205733e5f26aeee11bb4b469
BLAKE2b-256 0dea6d51b40a14877c2c0c4a59548edbf17cfade5fa01846807bb638a19b6242

See more details on using hashes here.

Provenance

The following attestation bundles were made for cobjectric-1.1.0-py3-none-any.whl:

Publisher: release.yml on nigiva/cobjectric

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page