Facets — Aquilia Documentation
Comprehensive guide and documentation for Facets in the Aquilia framework. View API reference, examples, and implementation patterns.
Docs / Contracts / Facets Facets Atomic field-level primitives of a Contract contract. Each Facet manages type coercion (cast), validation (seal), and output representation (mold). Base Facet Options from aquilia.contracts import Facet field = Facet( source="model_field", # read from distinct model attribute required=True, # fail CastFault if missing on inbound read_only=False, # exclude from inbound cast write_only=False, # exclude from outbound serialization default=None, # fallback value allow_null=False, # accept None allow_blank=False, # accept empty string (TextFacet only) validators=[], # additional validator callables ) Built-in Facets TextFacet Handles string properties with length boundaries and pattern matching. sku = TextFacet(max_length=50, pattern=r"^[A-Z0-9-]+$") IntFacet Coerces numeric strings/floats to integers. Validates min_value and max_value. Rejects booleans. quantity = IntFacet(min_value=1, max_value=99) Computed Derived read-only fields computed via a function or method. Can also use the @computed decorator. # Inline lambda computed facet full_name = Computed(lambda bp: f" ") # Method decorator pattern @computed def display_title(self) -> str: return self.instance.title.upper() Choice Constraint Restricts values to a specific set. Supports lists, dicts, or tuples: from aquilia.contracts import ChoiceFacet # List choices status = ChoiceFacet(choices=["draft", "published"]) # Dict choices (value -> description) priority = ChoiceFacet(choices= ) Facet Registry Reference Facet Python Target Description ))} Overview Projections )
Go to Homepage