Core shared utilities and foundational components for the Giskard library ecosystem.
Project description
Giskard Core
Core shared utilities and foundational components for the Giskard library ecosystem.
This package provides minimal, essential building blocks that are shared across all Giskard packages, including discriminated unions, error handling, type definitions, configuration patterns, and serialization utilities.
Installation
Using uv (recommended)
uv add giskard-core
For development, install with dev dependencies:
uv add giskard-core --dev
Using pip
pip install giskard-core
Requirements
- Python >= 3.11
- pydantic >= 2.11.0, < 3
Features
Discriminated Unions
A polymorphic type system with automatic serialization using a kind discriminator field. Subclasses are registered and resolved automatically during validation.
Basic Usage
from giskard.core import Discriminated, discriminated_base
# Mark a base class as a discriminated union
@discriminated_base
class Animal(Discriminated):
name: str
# Register concrete implementations
@Animal.register("dog")
class Dog(Animal):
breed: str
@Animal.register("cat")
class Cat(Animal):
lives: int = 9
# Create instances
dog = Dog(name="Buddy", breed="Labrador")
assert dog.kind == "dog"
# Serialize and deserialize
serialized = dog.model_dump()
# {"kind": "dog", "name": "Buddy", "breed": "Labrador"}
# Deserialize back to the correct type
animal = Animal.model_validate(serialized)
assert isinstance(animal, Dog)
assert animal.breed == "Labrador"
Advanced: Generic Types
The discriminated union system works seamlessly with Pydantic's generic types:
from typing import Generic, TypeVar
T = TypeVar("T")
@discriminated_base
class Container(Discriminated, Generic[T]):
value: T
@Container.register("string_container")
class StringContainer(Container[str]):
pass
@Container.register("int_container")
class IntContainer(Container[int]):
pass
Error Handling
A minimal, serializable error representation for consistent error handling across the Giskard ecosystem.
from giskard.core import Error
# Create an error
error = Error(message="Something went wrong")
# String representation
str(error) # "ERROR: Something went wrong"
# Serialize
error.model_dump() # {"message": "Something went wrong"}
API Reference
Discriminated
Base class for discriminated union types. Provides automatic serialization and deserialization based on a kind discriminator field.
Methods:
kind(property): Returns the discriminator string for the classregister(kind: str): Class method decorator to register a subclassmodel_validate(): Overridden to automatically resolve the correct subclass
discriminated_base
Decorator to mark a class as the base of a discriminated union. Use this on base classes that will have multiple concrete implementations.
Error
A serializable error class with a message field.
Fields:
message: str: The error message
Related Packages
- giskard-agents: Orchestrates LLM completions and agents in parallel workflows
- giskard-checks: Lightweight primitives to define and run checks against model interactions
- lidar: Probes LLM applications for security and safety issues
Development
Quick Setup
For quick development setup, use the provided Makefile:
make setup # Install deps + tools
make help # See all available commands
Manual Setup
Install the project dependencies:
uv sync
Common Tasks
make test # Run tests
make lint # Run linting
make format # Format code
make check-format # Check if code is formatted
make check # Run all checks (lint + format)
make clean # Clean build artifacts
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file giskard_core-0.1.0.tar.gz.
File metadata
- Download URL: giskard_core-0.1.0.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
468e39ee2d1b05d3042f6a88e9cb431c608b696d5ed708c1eba7f2a1eae4d0f0
|
|
| MD5 |
c29be2e21b83cc4340c3d756e40445e2
|
|
| BLAKE2b-256 |
5fbb82fb9f6749b1b4fbd40350494d533ab09178219b0c7174d0db794dec0b14
|
Provenance
The following attestation bundles were made for giskard_core-0.1.0.tar.gz:
Publisher:
tag-and-release.yml on Giskard-AI/giskard-core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
giskard_core-0.1.0.tar.gz -
Subject digest:
468e39ee2d1b05d3042f6a88e9cb431c608b696d5ed708c1eba7f2a1eae4d0f0 - Sigstore transparency entry: 686191068
- Sigstore integration time:
-
Permalink:
Giskard-AI/giskard-core@8486a7f1bf0e16f7649f6266409fc51c5e03d2d8 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Giskard-AI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
tag-and-release.yml@8486a7f1bf0e16f7649f6266409fc51c5e03d2d8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file giskard_core-0.1.0-py3-none-any.whl.
File metadata
- Download URL: giskard_core-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2274af9131a099a0e950aa03bd252c4fc3f2f526599b66762a2402db38cd99b9
|
|
| MD5 |
dc7df5ce65adc08f8347b5b9e5ca8293
|
|
| BLAKE2b-256 |
54d6a9e156bc36311ce8f40833a279ac212775f4b86158713f44f26d546dbf87
|
Provenance
The following attestation bundles were made for giskard_core-0.1.0-py3-none-any.whl:
Publisher:
tag-and-release.yml on Giskard-AI/giskard-core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
giskard_core-0.1.0-py3-none-any.whl -
Subject digest:
2274af9131a099a0e950aa03bd252c4fc3f2f526599b66762a2402db38cd99b9 - Sigstore transparency entry: 686191070
- Sigstore integration time:
-
Permalink:
Giskard-AI/giskard-core@8486a7f1bf0e16f7649f6266409fc51c5e03d2d8 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Giskard-AI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
tag-and-release.yml@8486a7f1bf0e16f7649f6266409fc51c5e03d2d8 -
Trigger Event:
push
-
Statement type: