From Python
The eutonomous package is the command line and a small library in one. Install it into
your project (pip install eutonomous) and use the key from eutonomous login, or set
EUTONOMOUS_API_KEY.
from eutonomous import Workspace
ws = Workspace(2038) # an environment id, or Workspace.for_project(".")
result = ws.deploy(".")
print(result.url if result.ok else result.error)
A workspace for one job
With a key that has the create permission, a script can make a workspace, use it and delete it:
with Workspace.create("scratch") as ws: # ready in about a minute
r = ws.run_python("print(6 * 7)")
print(r.stdout) # 42
# deleted here, with its files
Without the with block, nothing is deleted until you say so:
ws = Workspace.create("nightly")
ws.sleep() # stop paying for awake time; files stay
ws.exec("ls") # the next call wakes it, in a few seconds
ws.delete() # the workspace and every file in it
Workspace.list() # every environment the key can see
A new workspace counts against the number your account may have, and is billed from the same credits as one made on the platform.
Files
ws.write_file("data/in.csv", b"a,b\n1,2\n")
ws.read_file("data/in.csv") # bytes
ws.list_files("data") # name, type, size
ws.delete_file("data/in.csv")
Paths are relative to the workspace’s home directory.
Deploying
result = ws.deploy(".", wait=120) # ok, url, error
ws.releases() # what was deployed
ws.rollback() # back to the previous release
Running commands and reading logs
r = ws.exec("ls apps") # stdout, stderr and the exit code
print(r.stdout)
r = ws.run_python("import sys; print(sys.version)")
for kind, text in ws.exec_stream("pixi run test"): # "stdout", "stderr", then "exit"
if kind != "exit":
print(text, end="")
print(ws.logs(50)) # the app's last 50 lines
for line in ws.follow_logs(): # as they happen
print(line, end="")
Variables
ws.set_env({"DATABASE_URL": "postgres://…", "DEBUG": "0"})
ws.unset_env(["DEBUG"])
ws.env_names() # names only
Access, domains, always on
These need a key with the manage permission.
ws.set_access(public=False) # behind the eutonomous login
ws.add_domain("app.example.com") # waits for the certificate
ws.domains()
ws.remove_domain("app.example.com")
ws.always_on(True)
What a key may do is described under Keys and CI.