Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Swarmauri Logo

PyPI - Downloads Hits PyPI - Python Version PyPI - License PyPI - swarmauri_typing Discord

Swarmauri Typing

swarmauri_typing provides typing utilities for Swarmauri's dynamic component model. It exposes annotated intersection and union helpers used by swarmauri_base to build Pydantic-compatible component unions from runtime registries.

Why Swarmauri Typing?

swarmauri_typing isolates the small dynamic typing helpers used by Swarmauri's component model. It lets foundational packages generate metadata-rich Annotated unions without coupling those helpers to a specific component family.

FAQ

Q: What does UnionFactory do?

A: UnionFactory builds an Annotated[Union[...], ...] type from a caller-provided lookup function. swarmauri_base uses this pattern for dynamic component subtype unions.

Q: What does Intersection do?

A: Intersection computes common classes from input types and returns an annotated type that carries IntersectionMetadata.

Q: Do most application developers import this package directly?

A: Usually no. Most users get this behavior through swarmauri_base.DynamicBase and SubclassUnion.

Features

  • Intersection creates an annotated union of common classes from multiple input types.
  • IntersectionMetadata preserves the source classes used to build the intersection annotation.
  • UnionFactory builds annotated union types from a user-supplied type lookup function.
  • UnionFactoryMetadata records the source model or key used to build a dynamic union.
  • Annotation extenders allow callers to attach additional metadata such as Pydantic discriminators.
  • Python 3.10, 3.11, 3.12, 3.13, and 3.14 support.

Installation

Install with uv:

uv add swarmauri_typing

Install with pip:

pip install swarmauri_typing

Usage

Create an intersection annotation:

from typing import get_args

from swarmauri_typing import Intersection, IntersectionMetadata


class Root:
    pass


class Left(Root):
    pass


class Right(Root):
    pass


Common = Intersection[Left, Right]
metadata = [item for item in get_args(Common)[1:] if isinstance(item, IntersectionMetadata)]

assert metadata[0].classes == (Left, Right)

Create a dynamic annotated union:

from typing import Any

from swarmauri_typing import UnionFactory, UnionFactoryMetadata


class JsonStore:
    pass


class SqlStore:
    pass


def store_types(model_name: str) -> list[type]:
    if model_name == "Store":
        return [JsonStore, SqlStore]
    return []


StoreUnion = UnionFactory(store_types, name="store_union")["Store"]

assert any(
    isinstance(item, UnionFactoryMetadata) and item.name == "store_union"
    for item in getattr(StoreUnion, "__metadata__", ())
)

Swarmauri Component Usage

swarmauri_base.DynamicBase uses UnionFactory to turn registered component subtypes into discriminated unions. This lets models typed with SubclassUnion[BaseComponent] hydrate concrete subclasses from serialized payloads that include a type field.

from pydantic import Field

from swarmauri_typing import UnionFactory


def component_types(model_name: str) -> list[type]:
    return []


SubclassUnion = UnionFactory(
    component_types,
    name="subclass_union",
    annotation_extenders=[Field(discriminator="type")],
)

Foundational packages:

  • swarmauri_base uses these typing helpers for dynamic component deserialization.
  • swarmauri_core provides the interface contracts for Swarmauri component families.
  • swarmauri provides the namespace importer and plugin discovery layer.
  • swarmauri_standard provides first-party components that depend on the core/base typing model.

Component-kind packages that benefit from dynamic typing:

When To Use This Package

Use swarmauri_typing directly when you need dynamic Annotated type construction in a Swarmauri-compatible package. Most application developers interact with it indirectly through swarmauri_base.ComponentBase, DynamicBase, and SubclassUnion.

License

Apache-2.0

Contributing

When changing these helpers, keep the API small and compatible with Pydantic metadata usage in swarmauri_base, add focused tests for generated annotations, and follow the Swarmauri SDK contribution guide.

Metadata

Release files for swarmauri_typing 0.11.0.dev2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for swarmauri_typing 0.11.0.dev2
File Size Uploaded Provenance Actions
swarmauri_typing-0.11.0.dev2.tar.gz 9.3 kB Without provenance Details for swarmauri_typing-0.11.0.dev2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for swarmauri_typing 0.11.0.dev2
File Interpreter ABI Platform Actions
swarmauri_typing-0.11.0.dev2-py3-none-any.whl Python 3 none any Details for swarmauri_typing-0.11.0.dev2-py3-none-any.whl

Total release size: 19.6 kB

Release files / swarmauri_typing-0.11.0.dev2.tar.gz

Download URL swarmauri_typing-0.11.0.dev2.tar.gz
Size 9.3 kB
Tags Source
SHA-256 checksum
How to use checksums
2befa45aaedeeb4b5fe3ae2c648b754ec094196837b757aa7dd232ff065a23b2
BLAKE2b-256 checksum
How to use checksums
7f448b5ee2bd74481daeac4a1a1d90bac5030c7739a5f8202c4320045aa260e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / swarmauri_typing-0.11.0.dev2-py3-none-any.whl

Download URL swarmauri_typing-0.11.0.dev2-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
13a0fd08ae96f3e6a5b47bafb5fd3942ed91e346df8bc95baba0abef97b9e12e
BLAKE2b-256 checksum
How to use checksums
1376251db85c662ffc0099fb704c3da4869d1b051aa60394d2df781c783f6abb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for swarmauri_typing 0.11.0.dev2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page