Skip to main content

tidylinq

A set of utilities I've found useful when developing LLM tooling.

Usage:

from pydantic import BaseModel, Field
from textwrap import dedent
from tidylinq import from_iterable, completion_with_schema, retry

class Translation(BaseModel):
    term_source: str = Field(description="The source language term")
    term_target: str = Field(description="The term translated to the target language.")
    example_source: str = Field(description="Example of using the term in the source language.")
    example_target: str = Field(description="Example sentence target to the target language.")

messages = [
    {
        "role": "system",
        "content": dedent("""
            You are an expert translator. Output a structured Japanese response in JSON format for the provided English words.
        """).strip(),
    },
]

translations = (
    from_iterable(["cat", "dog", "hyena"])
    .select(
        lambda w: retry(completion_with_schema, backoff=1.0)(
            model="gemini/gemini-2.5-flash",
            messages=messages + [{"role": "user", "content": w}],
            response_schema=Translation,
        ),
        parallelism=4,
    )
    .with_progress("Translating words")
)

results = translations.to_list()
for translation in results:
    print(f"English: {translation.term_source}")
    print(f"Japanese: {translation.term_target}")
    print(f"Example (EN): {translation.example_source}")
    print(f"Example (JP): {translation.example_target}")

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tidylinq-0.2.0.tar.gz (113.7 kB view details)

Uploaded Source

Built Distribution

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

tidylinq-0.2.0-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file tidylinq-0.2.0.tar.gz.

File metadata

  • Download URL: tidylinq-0.2.0.tar.gz
  • Upload date:
  • Size: 113.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.0

File hashes

Hashes for tidylinq-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7513148a25bf5f47ed82e09b5fefd99fa4781383dcc2ef3510e12d01c1868bde
MD5 79d1680e7b8448050a0cd1dea0c266b0
BLAKE2b-256 0b70cdeae7a3ccdacb341f298c5c6a6116df361c7051e6f02af1c44ef31e349d

See more details on using hashes here.

File details

Details for the file tidylinq-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: tidylinq-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.0

File hashes

Hashes for tidylinq-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5c576724fca59539b7fd86c0850033538848000901ed7f7f206acaa2274197c0
MD5 98671e1c51a720a99075b19f2518e4ef
BLAKE2b-256 ffbd085b3dfc9377b73dc191ad7783933ca0081eda78233ea019c3d4bb6ab3c4

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 files

0.1.0

2 files

Supported by

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