Skip to main content

Tinfoil Python Library

PyPI - Version SDK Test Documentation

A Python client for secure AI model inference through Tinfoil.

Installation

# With uv
uv add tinfoil

# With pip
pip install tinfoil

Usage

The Tinfoil SDK automatically selects a router enclave and verifies it against the official GitHub repository. You just need to provide your API key:

import os
from tinfoil import TinfoilAI

client = TinfoilAI(
    api_key=os.getenv("TINFOIL_API_KEY")
)

chat_completion = client.chat.completions.create(
    model="llama3-3-70b",
    messages=[
        {
            "role": "user",
            "content": "Hi",
        }
    ],
)
print(chat_completion.choices[0].message.content)

Audio Transcription with Whisper

You can transcribe audio files using OpenAI's Whisper model:

import os
from tinfoil import TinfoilAI

client = TinfoilAI(
    api_key=os.getenv("TINFOIL_API_KEY")
)

with open("audio.mp3", "rb") as audio_file:
    transcription = client.audio.transcriptions.create(
        file=audio_file,
        model="whisper-large-v3-turbo",
    )
print(transcription.text)

Async Usage

Simply import AsyncTinfoilAI instead of TinfoilAI and use await with each API call:

import os
import asyncio
from tinfoil import AsyncTinfoilAI

client = AsyncTinfoilAI(
    api_key=os.getenv("TINFOIL_API_KEY")
)

async def main() -> None:
    stream = await client.chat.completions.create(
        model="llama3-3-70b",
        messages=[{"role": "user", "content": "Say this is a test"}],
        stream=True,
    )
    async for chunk in stream:
        if chunk.choices and chunk.choices[0].delta.content is not None:
            print(chunk.choices[0].delta.content, end="", flush=True)
    print()

asyncio.run(main())

Functionality between the synchronous and asynchronous clients is otherwise identical.

Low-level HTTP Endpoints

You can also perform arbitrary GET/POST requests that are verified:

import os
from tinfoil import NewSecureClient

api_key = os.getenv("TINFOIL_API_KEY")
tfclient = NewSecureClient()

# GET example
resp = tfclient.get(
    "https://example.com/health",
    headers={"Authorization": f"Bearer {api_key}"},
    params={"query": "value"},
    timeout=30,
)
print(resp.status_code, resp.text)

# POST example
payload = {"key": "value"}
resp = tfclient.post(
    "https://example.com/analyze",
    headers={
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json",
    },
    json=payload,
    timeout=30,
)
print(resp.status_code, resp.text)

Security

Please report security vulnerabilities by emailing security@tinfoil.sh.

We aim to respond to (legitimate) security reports within 24 hours.

Development

Install uv before following these instructions.

# Set up the development environment and install the package
uv sync

# Run all tests (requires the TINFOIL_API_KEY environment variable)
export TINFOIL_API_KEY="..."
uv run pytest

# Run unit tests
uv run pytest -m "not integration"

# Run integration tests (requires the TINFOIL_API_KEY environment variable)
export TINFOIL_API_KEY="..."
uv run pytest -m integration

Download files

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

Source Distribution

tinfoil-0.13.3.tar.gz (667.0 kB view details)

Uploaded Source

Built Distribution

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

tinfoil-0.13.3-py3-none-any.whl (93.3 kB view details)

Uploaded Python 3

File details

Details for the file tinfoil-0.13.3.tar.gz.

File metadata

  • Download URL: tinfoil-0.13.3.tar.gz
  • Upload date:
  • Size: 667.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for tinfoil-0.13.3.tar.gz
Algorithm Hash digest
SHA256 2cfd5ff0a7ec266090234c513d63fe4b650f288f3810b356b3aa8e2a2b929324
MD5 f861a33ec8117d8d9a8afcc4f9d7b1d7
BLAKE2b-256 931249d2906bad5a42ba9c74401980007f94145843ca4a088a8a65fefe5419e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for tinfoil-0.13.3.tar.gz:

Publisher: release.yml on tinfoilsh/tinfoil-python

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

File details

Details for the file tinfoil-0.13.3-py3-none-any.whl.

File metadata

  • Download URL: tinfoil-0.13.3-py3-none-any.whl
  • Upload date:
  • Size: 93.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for tinfoil-0.13.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c7afb4cd546372a6487f397bb67c0b849c6840896c77558e6bef0cfe3015a930
MD5 451e0bff023e0580e23557b8b334d998
BLAKE2b-256 c47099a08fcb410b0ce2b5c73f8c36fb2c85a8f2aa8d658c10ed87e0e8b46335

See more details on using hashes here.

Provenance

The following attestation bundles were made for tinfoil-0.13.3-py3-none-any.whl:

Publisher: release.yml on tinfoilsh/tinfoil-python

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

Release history Release notifications | RSS feed

0.14.0

2 files

0.13.6

2 files

0.13.5

2 files

0.13.4

2 files

This release

0.13.3 This release

2 files

0.13.1

2 files

0.13.0

2 files

0.12.2

2 files

0.12.1

2 files

0.11.5

2 files

0.11.4

2 files

0.11.2

2 files

0.11.1

2 files

0.11.0

2 files

0.10.1

2 files

0.10.0

2 files

0.4.1

2 files

0.4.0

2 files

0.3.0

2 files

0.2.2

2 files

0.2.0

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.2

5 files

0.1.1

5 files

0.1.0

5 files

0.0.35

2 files

0.0.34

5 files

0.0.33

5 files

0.0.31

5 files

0.0.30

5 files

0.0.29

13 files

0.0.27

13 files

0.0.24

13 files

0.0.23

13 files

0.0.20

13 files

0.0.19

13 files

0.0.16

13 files

0.0.9

18 files

0.0.8

3 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