Decorators#
API reference for every code-generating decorator. For usage, options, and examples, see the corresponding User Guide page linked from each section.
field#
- inito.field(*, default=<object object>, default_factory=None)[source]#
Declare a field’s default explicitly, e.g. a per-instance
default_factory.The inito-native equivalent of
dataclasses.field(): a mutable default such asitems: list = []is rejected (one object would be shared across every instance), so declare it asitems: list = field(default_factory=list)to build a fresh one per instance. ReturnsAnyso the annotated field type still type-checks.
Declare a field’s default explicitly — the inito-native equivalent of
dataclasses.field. Use field(default_factory=...) for a mutable default
(a bare items: list = [] is rejected) and field(default=...) for a plain
one. Recognized by the mypy plugin and by pyright (PEP 681 field_specifiers),
so the annotated field type still checks.
@Data / data#
- inito.Data#
Generate a constructor, __repr__, __eq__, and (per
accessors)get_/set_accessors for every declared field. A frozen class is also hashable; a mutable one is made unhashable (as dataclasses does) so a mutated instance can’t break its own set/dict membership. Accepts DataOptions (frozen, include_getters, include_setters, accessors).
- class inito.DataOptions(frozen=False, include_getters=True, include_setters=True, accessors='lombok', slots=False)[source]#
Configuration surface for the @Data decorator.
frozen=True skips setter generation and makes every field genuinely immutable: attribute assignment/deletion always raise dataclasses.FrozenInstanceError after construction, no @dataclass(frozen=True) stacking required. accessors selects the accessor style:
"lombok"(default,get_x/set_x),"attr"(none — useobj.xdirectly), or"both"(an alias of"lombok", since the attribute is always accessible in Python).
Also exported as inito.data. Guide: @Data.
@Value / value#
- inito.Value#
constructor, __repr__, __eq__, __hash__, and
get_accessors for every declared field - never setters. Attribute assignment and deletion always raise dataclasses.FrozenInstanceError after construction, unconditionally - no @dataclass(frozen=True) stacking required.
- class inito.ValueOptions(include_getters=True, slots=False, freeze_collections=False)[source]#
Configuration surface for the @Value decorator.
freeze_collections=True stores a mutable collection field as an immutable one (list->tuple, set->frozenset, dict->read-only mapping) at construction, hardening the shallow freeze that @Value already provides.
Also exported as inito.value. Generates a constructor, __repr__,
__eq__, __hash__, and get_ accessors — never setters, and genuinely
immutable (assignment/deletion raise dataclasses.FrozenInstanceError), with
no @dataclass(frozen=True) stacking. Guide: @Value.
@Getter / getter#
- inito.Getter#
Generate a get_<field>() accessor method for every declared field.
- class inito.GetterOptions[source]#
Configuration surface for the @Getter decorator (no options yet).
Also exported as inito.getter. Guide: Accessors.
@Setter / setter#
- inito.Setter#
Generate a set_<field>(value) mutator method for every declared field.
- class inito.SetterOptions[source]#
Configuration surface for the @Setter decorator (no options yet).
Also exported as inito.setter. Guide: Accessors.
@ToString / to_string#
- inito.ToString#
Generate a __repr__ listing every declared field.
- class inito.ToStringOptions[source]#
Configuration surface for the @ToString decorator (no options yet).
Also exported as inito.to_string. Guide: @ToString.
@EqualsAndHashCode / equals_and_hash_code#
- inito.EqualsAndHashCode#
Generate __eq__ and __hash__ over every declared field.
- class inito.EqualsAndHashCodeOptions[source]#
Configuration surface for the @EqualsAndHashCode decorator (no options yet).
Also exported as inito.equals_and_hash_code.
Guide: @EqualsAndHashCode.
@NoArgsConstructor / no_args_constructor#
- inito.NoArgsConstructor#
Generate a no-argument __init__ that assigns every field its default. Every field must have a default or default_factory, or decoration raises InvalidFieldDefinitionError.
- class inito.NoArgsConstructorOptions[source]#
Configuration surface for the @NoArgsConstructor decorator (no options yet).
Also exported as inito.no_args_constructor.
Guide: Constructors.
@AllArgsConstructor / all_args_constructor#
- inito.AllArgsConstructor#
Generate a constructor accepting every declared field.
- class inito.AllArgsConstructorOptions[source]#
Configuration surface for the @AllArgsConstructor decorator (no options yet).
Also exported as inito.all_args_constructor.
Guide: Constructors.
@RequiredArgsConstructor / required_args_constructor#
- inito.RequiredArgsConstructor#
Generate a constructor accepting only fields without a default; defaulted fields still get their default value assigned.
- class inito.RequiredArgsConstructorOptions[source]#
Configuration surface for the @RequiredArgsConstructor decorator (no options yet).
Also exported as inito.required_args_constructor.
Guide: Constructors.
@Builder / builder#
- inito.Builder#
Generate a nested fluent Builder class, a builder() classmethod, and (with to_builder=True) a to_builder() instance method. Accepts BuilderOptions (to_builder, setter_prefix, build_method_name, use_init). By default build() assigns fields directly, bypassing __init__ for speed; pass use_init=True to construct through the class’s own __init__ so a framework or hand-written constructor’s validation runs (e.g. Pydantic, SQLAlchemy, Django models).
- class inito.BuilderOptions(to_builder=False, setter_prefix='', build_method_name='build', use_init=False)[source]#
Configuration surface for the @Builder decorator.
Also exported as inito.builder. Guide: @Builder.
@Config / config#
- inito.Config#
Generate a zero-argument __init__ that loads each declared field from an environment variable (UPPER_SNAKE of the field name, with an optional prefix), coerced to the field’s annotated type, at construction time. Fields without an env value fall back to their default; a required field with neither raises ConfigResolutionError. Register a @Config class as a @Service to autowire it by type. Accepts ConfigOptions(prefix).
- class inito.ConfigOptions(prefix='')[source]#
Configuration surface for the @Config decorator.
- Parameters:
prefix (str)
Also exported as inito.config. Guide: @Config.
@Jsonize / jsonize#
- inito.Jsonize#
Generate to_dict() (a JSON-native dict) and to_json() (a JSON string) over every declared field, coercing datetime/date/time (ISO 8601), UUID, Decimal, Enum, bytes (base64), Path, mappings, sequences/sets, and nested @Jsonize objects. to_json forwards its keyword arguments to json.dumps.
- class inito.JsonizeOptions[source]#
Configuration surface for the @Jsonize decorator (no options yet).
Also exported as inito.jsonize. Generates to_dict()/to_json() serializing
every declared field (datetime, UUID, Decimal, Enum, bytes, Path, nested
@Jsonize, …) to JSON-native forms. Guide: @Jsonize.