Skip to main content

The cyanotype process, which gave birth to the "blueprint", uses iron salts and UV light to transform simple negatives into deep Prussian blue artwork.

Features

Cyantic lets you build complex types from simple blueprints, using Pydantic.

  • Build complex objects using intermediate Pydantic models.
  • Reference other values using @value:x.y.z
  • Import objects using @import:x.y.z
  • Define custom @hook handlers (see tests)

Installation

  • uv add cyantic

Usage

from cyantic import Blueprint, blueprint, CyanticModel, hook
from torch import Tensor
import torch
import yaml

# 1. Create and register some useful parameterisations
#       (or soon install from PyPi, i.e. `rye add cyantic-torch`)

@blueprint(Tensor)
class NormalTensor(Blueprint[Tensor]):

    mean: float
    std: float
    size: tuple[int, ...]

    def build(self) -> Tensor:
        return torch.normal(self.mean, self.std, size=self.size)

@blueprint(Tensor)
class UniformTensor(Blueprint[Tensor]):
    low: float
    high: float
    size: tuple[int, ...]

    def build(self) -> Tensor:
      return torch.empty(self.size).uniform_(self.low, self.high)


# 2. Write pydantic models using `CyanticModel` base class

class MyModel(CyanticModel):
    normal_tensor: Tensor
    uniform_tensor: Tensor


# 3. (optional) define custom hooks

@hook("env")
def env_hook(name: str, _: ValidationContext) -> str:
    """Handle @env:VARIABLE_NAME references."""
    try:
        return os.environ[name]
    except KeyError as e:
        raise ValueError(f"Environment variable {name} not found") from e


# 4. Validate from YAML files that specify the parameterisation

some_yaml = """common:
    size: [3, 5]
    foo: @env:MY_VARIABLE
normal_tensor:
    mean: 0.0
    std: 0.1
    size: @value:common.size
uniform_tensor:
    low: -1.0
    std: 1.0
    size: @value:common.size
"""

# 4. Receive objects built from the parameterisations.

my_model = MyModel.model_validate(yaml.safe_load(some_yaml))
assert isinstance(my_model.normal_tensor, Tensor)
assert isinstance(my_model.uniform_tensor, Tensor)

Development

  • git clone https://github.com/flywhl/cyantic.git
  • cd cyantic
  • uv sync
  • just test

Flywheel

Science needs humble software tools. Flywheel is an open source collective building simple tools to preserve scientific momentum, inspired by devtools and devops culture.

Metadata

Release files for cyantic 0.3.0

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

Source distribution (sdist)

Source distribution for cyantic 0.3.0
File Size Uploaded Provenance Actions
cyantic-0.3.0.tar.gz 43.3 kB Without provenance Details for cyantic-0.3.0.tar.gz

Built distribution (wheel)

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

Total release size: 54.2 kB

Release files / cyantic-0.3.0.tar.gz

Download URL cyantic-0.3.0.tar.gz
Size 43.3 kB
Tags Source
SHA-256 checksum
How to use checksums
941623cc362d07ee9a0ac26b1de2202d1c1708e03d9ebaa7f4d2b01ea064834b
BLAKE2b-256 checksum
How to use checksums
00b366e5edb4fdc85ffcf24dfbb7e4ce4f6852ae62a811aba6ac4e8806268fd6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.5.16

Release files / cyantic-0.3.0-py3-none-any.whl

Download URL cyantic-0.3.0-py3-none-any.whl
Size 10.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
96a9b8d01667781835d52f58248b775a49dc13aff4294d05b6cbf2b480dca29f
BLAKE2b-256 checksum
How to use checksums
f858ae24c37b8dd48b4e6fad41daf0dc1e25fe3a7aef2d804904e1f21cb05ab1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.5.16

Security for cyantic 0.3.0

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.

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