Skip to main content

Official Python SDK for the Tyto API

Project description

tyto

Python SDK for the Tyto API — manage nests, sessions, files, previews, snapshots, and keepalive holds.

Install

pip install tyto

Auth

Export your API key:

export TYTO_API_KEY=your_key_here

Or pass it directly:

from tyto import Tyto
tyto = Tyto(api_key="your_key_here")

Usage

import os
from tyto import Tyto

tyto = Tyto(api_key=os.environ["TYTO_API_KEY"])

# Who am I?
me = tyto.me()
print(me.email)

# Create a nest
nest = tyto.create(name="my-nest", template="ubuntu-24-dev")

# Upload / download a file or directory
nest.put("./hello.txt", "hello.txt")
nest.get("hello.txt", "./hello.downloaded.txt")

# Create a session and attach over WebSocket
session = nest.create_session(argv=["bash", "-lc", "echo hi"], tty=False)
with session.attach() as ws:
    for message in ws:
        print(message)

# Open raw WebSocket connections
with nest.exec() as ws: ...
with nest.console() as ws: ...

# Create a preview
preview = nest.create_preview(port=3000, auth="private")
print(preview.url)

# Snapshot, fork, restore
snap = nest.create_snapshot(name="v1")
fork = nest.fork(name="my-fork")
nest.delete_snapshot(snap.id)
# nest.restore(snap.id)

# Keepalive hold
nest.holds.put("ci", ttl="30m", reason="CI job")
nest.holds.heartbeat("ci", ttl="30m")
nest.holds.delete("ci")

# Lifecycle
nest.stop()
nest.start()
nest.wake(reason="wakeup")
nest.delete()

Resources

Resource Description
tyto.create() Create a nest
tyto.nests Create / list / get nests
tyto.previews Inspect / revoke previews by ID
tyto.auth CLI browser auth flow
nest.put(local, remote) Upload a file or directory
nest.get(remote, local) Download a file or directory
nest.create_session() Create a managed session
nest.create_preview() Create a preview URL
nest.create_snapshot() Create a snapshot
nest.delete_snapshot() Delete a snapshot
nest.fs Low-level file upload / download
nest.sessions Managed sessions (create / list)
nest.previews Previews scoped to the nest
nest.snapshots Snapshots + fork/restore
nest.holds Keepalive holds
session.attach() WebSocket stream for a session
nest.console() Interactive shell WebSocket
nest.exec() Command WebSocket

Configuration

Parameter Env var Default
api_key TYTO_API_KEY — (required)
api_url TYTO_API_URL https://api.tyto.run

Examples

python examples/quickstart.py
python examples/files.py
python examples/preview.py
python examples/snapshot_fork.py
python examples/websocket_exec.py

Context manager

The Tyto client can be used as a context manager to ensure the underlying HTTP connection pool is closed:

with Tyto() as tyto:
    nests = tyto.nests.list()

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

tyto_run-0.11.0.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

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

tyto_run-0.11.0-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file tyto_run-0.11.0.tar.gz.

File metadata

  • Download URL: tyto_run-0.11.0.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.5

File hashes

Hashes for tyto_run-0.11.0.tar.gz
Algorithm Hash digest
SHA256 14cd662541eeb619e92f058db87b68e948c7f17bdd0663d6dfce6f26fd516621
MD5 2ccc6d65f447b7228427f6957b747a57
BLAKE2b-256 e4baa6b4df71b0356c276b0a6115ebb676eb10cafebdad3bf14a0d4034ea2f6d

See more details on using hashes here.

File details

Details for the file tyto_run-0.11.0-py3-none-any.whl.

File metadata

  • Download URL: tyto_run-0.11.0-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.5

File hashes

Hashes for tyto_run-0.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5500b36407c275fcdc675822e011dda6f0865ebe938d610d16fa566d7b57bb2c
MD5 8a0a1533027c77d0c0764ed15d5c79bb
BLAKE2b-256 dc09f6014d52a7e90bbc98e39b731e1486a980d6af3ac9196516146a66453c3d

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