Skip to main content

Type-friendly utilities for moving data between Python objects, Arrow, Polars, Pandas, Spark, and Databricks

Project description

Yggdrasil (Python package)

Yggdrasil (ygg on PyPI, yggdrasil in imports) is a schema-aware data interchange library. It centers on an Arrow-first conversion registry that can cast values across Python types, Arrow, Polars, pandas, Spark, and Databricks-oriented workflows.

Install

cd python
uv venv .venv
source .venv/bin/activate
uv pip install -e .[dev]

Install optional integrations only when needed:

uv pip install -e .[polars]
uv pip install -e .[pandas]
uv pip install -e .[spark]
uv pip install -e .[databricks]
uv pip install -e .[api]
uv pip install -e .[pickle]

Progressive examples (easy → advanced)

1) Cast a scalar value

from yggdrasil.data.cast.registry import convert

age = convert("42", int)
active = convert("true", bool)
print(age, active)  # 42 True

2) Cast a dictionary into a dataclass

from dataclasses import dataclass
from yggdrasil.data.cast.registry import convert

@dataclass
class User:
    id: int
    email: str
    active: bool = True

payload = {"id": "7", "email": "ada@example.com", "active": "false"}
user = convert(payload, User)
print(user)  # User(id=7, email='ada@example.com', active=False)

3) Infer Arrow schema from Python hints

import yggdrasil.arrow as pa
from yggdrasil.arrow import arrow_field_from_hint

field = arrow_field_from_hint(list[int], name="scores")
schema = pa.schema([field])
print(schema)

4) Cast Arrow table with explicit CastOptions

import yggdrasil.arrow as pa
from yggdrasil.arrow.cast import cast_arrow_tabular
from yggdrasil.data.cast.options import CastOptions

raw = pa.table({"id": ["1", "2"], "score": ["9.1", "8.7"]})
target = pa.schema([
    pa.field("id", pa.int64(), nullable=False),
    pa.field("score", pa.float64(), nullable=False),
])

out = cast_arrow_tabular(raw, CastOptions(target_field=target, strict_match_names=True))
print(out.schema)

5) Use lazy optional dependency guards (lib.py pattern)

from yggdrasil.polars.lib import polars
from yggdrasil.pandas.lib import pandas

pl_df = polars.DataFrame({"id": [1, 2]})
pd_df = pandas.DataFrame({"id": [1, 2]})

6) Use IO buffers + HTTP session

from yggdrasil.io import BytesIO
from yggdrasil.io.http_ import HTTPSession

with BytesIO() as buf:
    buf.write(b"hello")
    buf.seek(0)
    print(buf.media_type)

session = HTTPSession()
response = session.get("https://example.com")
print(response.status)

Batch + prepared requests:

from yggdrasil.io.http_ import HTTPSession

http = HTTPSession()
req = http.prepare_request("POST", "https://httpbin.org/post", json={"x": 1})
resp = http.send(req)
print(resp.status, resp.json().get("json"))

7) Databricks SQL execution (Arrow-first results)

from yggdrasil.databricks import DatabricksClient

stmt = DatabricksClient(host="https://<workspace>", token="<token>").sql.execute("SELECT 1 AS value")
print(stmt.to_arrow_table())

8) Utility decorators for retries and concurrency

from yggdrasil.pyutils import retry, parallelize

@retry(tries=3, delay=0.1, backoff=2)
def flaky(x: int) -> int:
    return x

@parallelize(max_workers=4)
def square(x: int) -> int:
    return x * x

print(list(square(range(5))))

Documentation map

  • docs/README.md – full Python docs walkthrough.
  • docs/modules.md – concise module index.
  • docs/modules/* – focused module pages for core APIs.

Documentation website

Development checks

cd python
pytest
ruff check
black .

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

ygg-0.7.12.tar.gz (666.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ygg-0.7.12-py3-none-any.whl (792.8 kB view details)

Uploaded Python 3

File details

Details for the file ygg-0.7.12.tar.gz.

File metadata

  • Download URL: ygg-0.7.12.tar.gz
  • Upload date:
  • Size: 666.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","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}

File hashes

Hashes for ygg-0.7.12.tar.gz
Algorithm Hash digest
SHA256 d7ba63dd35a634eb506ddb53ee5205edd7136f3f0b33a4b895e1adbc52590f82
MD5 22824522e6e61abb491fc0d33e80c54a
BLAKE2b-256 382d2dd82a4cf257a232c2950f5b9bc938d558bb97f67aa76b0923cec776fc9d

See more details on using hashes here.

File details

Details for the file ygg-0.7.12-py3-none-any.whl.

File metadata

  • Download URL: ygg-0.7.12-py3-none-any.whl
  • Upload date:
  • Size: 792.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","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}

File hashes

Hashes for ygg-0.7.12-py3-none-any.whl
Algorithm Hash digest
SHA256 e079f250d7cacef657168cc5a49e870bc6d2d2c77dc305ea47de3f8ebb8ddf22
MD5 4d379cf2d3a7435062352550330a81f0
BLAKE2b-256 0304472139299f5d17eb3c46c5220562fe79c2ad956cc75863dec520da50a4ee

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page