Registry / serialization / cobble

cobble

JSON →
library0.1.4pypypi✓ verified 25d ago

Cobble is a Python library designed for the easy creation of data objects. It automatically implements common methods such as `__eq__` and `__repr__`, simplifying the boilerplate typically associated with simple data-holding classes. The current version is 0.1.4, released on June 1, 2024, and it is actively maintained with a stable release cadence.

pip install cobble
INSTALL
IMPORT
SIG · COBBLE
C
cobble
serializationpythonv0.1.4
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

data
from cobble import data
import cobble @cobble.data

This example demonstrates how to define a simple data object `Song` using the `@cobble.data` decorator and `cobble.field()`. It also shows how to create a more complex structure like an expression tree with `Literal` and `Add` and then process it using a visitor pattern with `cobble.visitor`.

import cobble @cobble.data class Song(object): name = cobble.field() artist = cobble.field() album = cobble.field(default=None) song = Song("MFEO", artist="Jack's Mannequin", album="Everything in Transit") print(song) @cobble.data class Literal: value = cobble.field() @cobble.data class Add: left = cobble.field() right = cobble.field() class Evaluator(cobble.visitor(object)): def visit_literal(self, literal): return literal.value def visit_add(self, add): return self.visit(add.left) + self.visit(add.right) expression = Add(Literal(2), Literal(4)) result = Evaluator().visit(expression) print(f"Evaluation of {expression} is: {result}")
Debug
Known issues
gotchaMutable default arguments in `cobble.field(default=...)` can lead to unexpected shared state across instances. This is a common Python footgun, also applicable to `dataclasses` and `cobble`.
fix
Use `default_factory` for mutable defaults, e.g., `my_list = cobble.field(default_factory=list)`.
affects: All versions
gotchaOverriding `__init__` in a `cobble.data` class will prevent Cobble from automatically generating its own `__init__` method, potentially leading to uninitialized fields or `AttributeError` if not handled carefully.
fix
Prefer using `__post_init__` for custom initialization logic or ensure your custom `__init__` explicitly initializes all fields defined by `cobble.field()`.
affects: All versions
gotchaAccessing fields directly on a `cobble.data` class before instantiation (e.g., `MyClass.field_name`) will result in an `AttributeError` if the field is intended for instances.
fix
Always instantiate the class (e.g., `instance = MyClass(...)`) before attempting to access instance-specific fields. Use `typing.ClassVar` if an attribute truly needs to be a class-level variable and should not be part of the `__init__` generated by `cobble`.
affects: All versions
Upgrade
Version history
0.1.4latest on PyPI · released Jun 1, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
21 hits · last 30 days
node
18
OpenAI (training)
1
Resources
cobble — pip install cobble · libregistry