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.run

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.12.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.12.0-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tyto_run-0.12.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.12.0.tar.gz
Algorithm Hash digest
SHA256 fc08c6b2593cb09183a8eed8fa6ee9fd614792f73c8371631f7802d2bd9022f0
MD5 28b2315a0acccc216297285530cc5c5d
BLAKE2b-256 a4038c2f0366f25805bf74794f41276d7b161fe4ef6b22a5e9bf459a5bd198cd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tyto_run-0.12.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.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e772dee9e58f2db0b08901346130d33b7a9230f12140ea502b986b39b1e28118
MD5 0b0fd0d3edc856ce0bd10df01c2b375d
BLAKE2b-256 e384a31e5a2ce07f7be3e35421a12e4be6b79c65e4c3bc69fc4f5ccc74c88298

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