Skip to main content

Python SDK for Gretl — control local services by name or port number

Project description

gretl

Python SDK for Gretl — control local services by name or port number.

Install

pip install gretl

Quick start

from gretl import gr

# List all monitored ports
ports = gr.ports()

# Start / stop by name or port number
gr.start("api")
gr.stop("3000")

# Start / stop an entire group
gr.start_group("backend")
gr.stop_group("backend")

# Wait for a service to come up (useful in tests)
gr.wait_for_active("postgres", timeout=30)

# Add a new port to monitoring
gr.add(7401, name="jobs-server", cmd="node jobs.js", group="backend")

API

Method Description
gr.ports() Return all monitored ports
gr.port(query) Find ports by name substring or exact port number
gr.active() Only running ports
gr.inactive() Only stopped ports
gr.start(query) Start matching service(s)
gr.stop(query) Stop matching service(s)
gr.remove(query) Remove from monitoring
gr.start_group(group) Start all ports in a group
gr.stop_group(group) Stop all ports in a group
gr.status_group(group) List all ports in a group
gr.wait_for_active(query, timeout, interval) Block until active
gr.wait_for_inactive(query, timeout, interval) Block until inactive
gr.add(port, name, cmd, group, cwd) Register a new port

Kubernetes & cloud

gr.k8s exposes the Gretl cloud API for managing Kubernetes workloads. Set GR_TOKEN in your environment or pass token= to GretlClient.

from gretl import gr
# GR_TOKEN is read automatically from os.environ

clusters = gr.k8s.clusters()
workloads = gr.k8s.workloads(cluster_id=clusters[0]["id"])

# Sleep / wake a workload
gr.k8s.sleep(workloads[0]["id"])
gr.k8s.wake(workloads[0]["id"])

# Tether a container port to a public tunnel URL
tether = gr.k8s.tether(workloads[0]["id"], container_port=8000)
print(tether["tunnel_url"])

# Force a cluster sync
gr.k8s.sync(clusters[0]["id"])

# Configure auto-sleep
gr.k8s.set_auto_sleep(workloads[0]["id"], enabled=True, idle_timeout_minutes=30)
Method Description
gr.k8s.clusters() List connected clusters
gr.k8s.workloads(cluster_id=None) List workloads
gr.k8s.sync(cluster_id) Force cluster sync
gr.k8s.sleep(workload_id) Scale to zero
gr.k8s.wake(workload_id) Restore replicas
gr.k8s.tether(workload_id, container_port, label=None) Create public tunnel
gr.k8s.detach(tether_id) Deactivate a tether
gr.k8s.tethers() List active tethers
gr.k8s.auto_sleep(workload_id) Get auto-sleep config
gr.k8s.set_auto_sleep(workload_id, enabled, idle_timeout_minutes) Update auto-sleep config

Requirements

The Gretl daemon must be running for local port methods. Download free at gretl.dev. K8s methods require a GR_TOKEN from your Gretl dashboard.

Links

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

gretl-1.1.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

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

gretl-1.1.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file gretl-1.1.0.tar.gz.

File metadata

  • Download URL: gretl-1.1.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for gretl-1.1.0.tar.gz
Algorithm Hash digest
SHA256 cb7c236553a9063e523697cf7ff027af5f75cde4e3466b41fe85cf0ba8772677
MD5 638a7ea659a5d14ba8717dc109644a29
BLAKE2b-256 5436acb039917aa90c0401788b538f588d0d3972fe392b1dbf876e868f9c0f69

See more details on using hashes here.

File details

Details for the file gretl-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: gretl-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for gretl-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2c011ca43f85cc17c274ed017ddd4f894568376193fca57a29bfc85914133c7e
MD5 a270ebe8b8859eb8b9131d5e1ad9781d
BLAKE2b-256 ab755fed539f56d173360b4a789eda5cfbcf14a45a0b564c1d33b01d97659cba

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