Python client for Tinfoil
Project description
Tinfoil Python Library
A Python client for secure AI model inference through Tinfoil.
Installation
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
tfclient = NewSecureClient(
api_key=os.getenv("TINFOIL_API_KEY"),
)
# GET example
resp = tfclient.get(
"https://example.com/health",
params={"query": "value"},
timeout=30,
)
print(resp.status_code, resp.text)
# POST example
payload = {"key": "value"}
resp = tfclient.post(
"https://example.com/analyze",
headers={"Content-Type": "application/json"},
json=payload,
timeout=30,
)
print(resp.status_code, resp.text)
Requirements
- Python 3.10 through 3.13
Testing
Run unit and integration tests:
pytest -q
Integration tests require the TINFOIL_API_KEY environment variable:
export TINFOIL_API_KEY="..."
pytest -q -m integration
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 tinfoil-0.11.2.tar.gz.
File metadata
- Download URL: tinfoil-0.11.2.tar.gz
- Upload date:
- Size: 118.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22fd0c433cbb75489fb0dd56fac7543990cee1fd2a8a46061736e8395dc6c594
|
|
| MD5 |
92d4cb5ca3005fa60872c393c5f4bfca
|
|
| BLAKE2b-256 |
0f5060c22aba28031967783eaff7c3d1042a7f0a8256e241d98cdf7457095ad0
|
Provenance
The following attestation bundles were made for tinfoil-0.11.2.tar.gz:
Publisher:
build.yml on tinfoilsh/tinfoil-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tinfoil-0.11.2.tar.gz -
Subject digest:
22fd0c433cbb75489fb0dd56fac7543990cee1fd2a8a46061736e8395dc6c594 - Sigstore transparency entry: 1219613189
- Sigstore integration time:
-
Permalink:
tinfoilsh/tinfoil-python@a4b9fa5ece3e778a8c67f1edd6685610e9c61723 -
Branch / Tag:
refs/tags/v0.11.2 - Owner: https://github.com/tinfoilsh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@a4b9fa5ece3e778a8c67f1edd6685610e9c61723 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tinfoil-0.11.2-py3-none-any.whl.
File metadata
- Download URL: tinfoil-0.11.2-py3-none-any.whl
- Upload date:
- Size: 85.3 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 |
930baae966022a53bdfd7718dc1800d1147bd3f211e5a24178f6536b20b7df19
|
|
| MD5 |
2dcc17d95d5834faa686ddb3a6675cfb
|
|
| BLAKE2b-256 |
297833a1ef2e1f02c5409224f357d41154f6e039c721a5a8d127f694b6a46c30
|
Provenance
The following attestation bundles were made for tinfoil-0.11.2-py3-none-any.whl:
Publisher:
build.yml on tinfoilsh/tinfoil-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tinfoil-0.11.2-py3-none-any.whl -
Subject digest:
930baae966022a53bdfd7718dc1800d1147bd3f211e5a24178f6536b20b7df19 - Sigstore transparency entry: 1219613268
- Sigstore integration time:
-
Permalink:
tinfoilsh/tinfoil-python@a4b9fa5ece3e778a8c67f1edd6685610e9c61723 -
Branch / Tag:
refs/tags/v0.11.2 - Owner: https://github.com/tinfoilsh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@a4b9fa5ece3e778a8c67f1edd6685610e9c61723 -
Trigger Event:
push
-
Statement type: