Skip to main content

A lightweight Python SDK for the Pythinker API.

Reason this release was yanked:

Released alongside aborted pythinker-cli line; pythinker-code is the canonical name.

Project description

Pythinker SDK

Pythinker SDK provides a convenient way to access the Pythinker API and build agent workflows in Python.

Installation

Pythinker SDK requires Python 3.12 or higher. We recommend using uv as the package manager.

uv init --python 3.12  # or higher

Then add Pythinker SDK as a dependency:

uv add pythinker-sdk

Examples

Simple chat completion

import asyncio

from pythinker_sdk import Pythinker, Message, generate


async def main() -> None:
    pythinker = Pythinker(
        base_url="https://api.pythinker-ai.ai/v1",
        api_key="your_pythinker_api_key_here",
        model="pythinker-ai",
    )

    history = [
        Message(role="user", content="Who are you?"),
    ]

    result = await generate(
        chat_provider=pythinker,
        system_prompt="You are a helpful assistant.",
        tools=[],
        history=history,
    )
    print(result.message)
    print(result.usage)


asyncio.run(main())

Streaming output

import asyncio

from pythinker_sdk import Pythinker, Message, StreamedMessagePart, generate


async def main() -> None:
    pythinker = Pythinker(
        base_url="https://api.pythinker-ai.ai/v1",
        api_key="your_pythinker_api_key_here",
        model="pythinker-ai",
    )

    history = [
        Message(role="user", content="Who are you?"),
    ]

    def output(message_part: StreamedMessagePart) -> None:
        print(message_part)

    result = await generate(
        chat_provider=pythinker,
        system_prompt="You are a helpful assistant.",
        tools=[],
        history=history,
        on_message_part=output,
    )
    print(result.message)
    print(result.usage)


asyncio.run(main())

Upload video

import asyncio
from pathlib import Path
from pythinker_sdk import Pythinker, Message, TextPart, generate


async def main() -> None:
    pythinker = Pythinker(
        base_url="https://api.pythinker-ai.ai/v1",
        api_key="your_pythinker_api_key_here",
        model="pythinker-ai",
    )

    video_path = Path("demo.mp4")
    video_part = await pythinker.files.upload_video(
        data=video_path.read_bytes(),
        mime_type="video/mp4",
    )

    history = [
        Message(
            role="user",
            content=[
                TextPart(text="Please describe this video."),
                video_part,
            ],
        ),
    ]

    result = await generate(
        chat_provider=pythinker,
        system_prompt="You are a helpful assistant.",
        tools=[],
        history=history,
    )
    print(result.message)
    print(result.usage)


asyncio.run(main())

Tool calling with step

import asyncio

from pydantic import BaseModel

from pythinker_sdk import CallableTool2, Pythinker, Message, SimpleToolset, StepResult, ToolOk, ToolReturnValue, step


class AddToolParams(BaseModel):
    a: int
    b: int


class AddTool(CallableTool2[AddToolParams]):
    name: str = "add"
    description: str = "Add two integers."
    params: type[AddToolParams] = AddToolParams

    async def __call__(self, params: AddToolParams) -> ToolReturnValue:
        return ToolOk(output=str(params.a + params.b))


async def main() -> None:
    pythinker = Pythinker(
        base_url="https://api.pythinker-ai.ai/v1",
        api_key="your_pythinker_api_key_here",
        model="pythinker-ai",
    )

    toolset = SimpleToolset()
    toolset += AddTool()

    history = [
        Message(role="user", content="Please add 2 and 3 with the add tool."),
    ]

    result: StepResult = await step(
        chat_provider=pythinker,
        system_prompt="You are a precise math tutor.",
        toolset=toolset,
        history=history,
    )
    print(result.message)
    print(await result.tool_results())


asyncio.run(main())

Environment variables

  • PYTHINKER_API_KEY: API key for the Pythinker API.
  • PYTHINKER_BASE_URL: Override the API base URL (defaults to https://api.pythinker-ai.ai/v1).

Project details


Download files

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

Source Distribution

pythinker_sdk-1.0.0.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

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

pythinker_sdk-1.0.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file pythinker_sdk-1.0.0.tar.gz.

File metadata

  • Download URL: pythinker_sdk-1.0.0.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pythinker_sdk-1.0.0.tar.gz
Algorithm Hash digest
SHA256 6359ee4793bbf5c530f3e84e46e4e79406e192cdc0e1074dbe585c4be040adf6
MD5 ff8184d081abad24180414d07de67420
BLAKE2b-256 f5a4568853dfea0206c079c6acd623565751946d136695420143cc9007665740

See more details on using hashes here.

Provenance

The following attestation bundles were made for pythinker_sdk-1.0.0.tar.gz:

Publisher: release-pythinker-sdk.yml on mohamed-elkholy95/Pythinker-Code

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pythinker_sdk-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pythinker_sdk-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pythinker_sdk-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4bf83694553db80555683ab560f90594508f95fa39626d8ca75cef866009fa22
MD5 663cd00475cb91359b78d48039e5ac7f
BLAKE2b-256 5b4f1a27ea63da5a35b11606afc833b2c897c40d01031f15ff57707a816a2ecc

See more details on using hashes here.

Provenance

The following attestation bundles were made for pythinker_sdk-1.0.0-py3-none-any.whl:

Publisher: release-pythinker-sdk.yml on mohamed-elkholy95/Pythinker-Code

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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