schedr.connection_types

The built-in connection types: one definition for every kind of task (decisions 174, 183).

billing_api = HTTP("billing_api", base_url=..., token=secrets["billing"]["token"]) is a connection as @connection makes one, its name the first argument: tasks declare it (connections=[billing_api]) and open it (with billing_api() as client:), getting the type’s client. Each client’s library is an extra (schedr[http], schedr[ssh], schedr[mongo], schedr[postgres], schedr[mysql]), imported only when a connection is opened, so import schedr needs none of them. Every type has a check (schedr connections test NAME): HTTP a request, SSH connecting, Mongo a ping, SQL a SELECT 1.

class schedr.connection_types.HTTP(name, /, *, base_url, token=None, user=None, password=None, headers=None, ca_cert=None, client_cert=None, client_key=None, timeout=30.0, check_path=None)

Bases: TwoWayConnection[object, object]

An HTTP API: an httpx.Client with its base URL, authentication and TLS settings.

with billing_api() as client: client.get("/invoices"); async with gives an httpx.AsyncClient.

Parameters:
  • name (str)

  • base_url (str)

  • token (str | None)

  • user (str | None)

  • password (str | None)

  • headers (dict[str, str] | None)

  • ca_cert (str | None)

  • client_cert (str | None)

  • client_key (str | None)

  • timeout (float)

  • check_path (str | None)

class schedr.connection_types.SQL(name, /, *, url, user=None, password=None, ca_cert=None, timeout=30.0)

Bases: TwoWayConnection[DbApiConnection, object]

A Postgres or MySQL database, by URL: a DB-API connection (psycopg 3, PyMySQL).

with warehouse() as db: cursor = db.cursor(); the block’s work is committed when it ends, rolled back on an error, as psycopg’s own with does.

TLS is libpq’s sslmode in the URL, for both: verify-full (the default) needs TLS and checks the server’s certificate and name, against ca_cert or the system’s CAs; verify-ca the certificate only; require TLS, unchecked; prefer and allow TLS when offered; disable none (?sslmode=disable, for a server without TLS).

Parameters:
  • name (str)

  • url (str)

  • user (str | None)

  • password (str | None)

  • ca_cert (str | None)

  • timeout (float)

class schedr.connection_types.SSH(name, /, *, host, user, port=22, private_key=None, passphrase=None, password=None, known_hosts=None, insecure_skip_host_check=False, timeout=30.0)

Bases: Connection[object]

An SSH host (network devices too): a connected paramiko SSHClient.

with router() as client: client.exec_command("show version"). The host’s key must be in known_hosts; insecure_skip_host_check=True accepts any, loudly.

Parameters:
  • name (str)

  • host (str)

  • user (str)

  • port (int)

  • private_key (str | None)

  • passphrase (str | None)

  • password (str | None)

  • known_hosts (str | None)

  • insecure_skip_host_check (bool)

  • timeout (float)

class schedr.connection_types.DbApiConnection(*args, **kwargs)

Bases: Protocol

A DB-API connection, as psycopg’s and PyMySQL’s are.

cursor()

A new cursor.

Return type:

DbApiCursor

commit()

Commits the transaction.

Return type:

None

rollback()

Rolls it back.

Return type:

None

close()

Closes the connection.

Return type:

None

class schedr.connection_types.DbApiCursor(*args, **kwargs)

Bases: Protocol

A DB-API cursor, as psycopg’s and PyMySQL’s are.

execute(query, params=Ellipsis, /)

Runs a query.

Parameters:
  • query (str)

  • params (Sequence[object] | None)

Return type:

object

fetchone()

The next row.

Return type:

Sequence[object] | None

fetchall()

The remaining rows.

Return type:

Sequence[Sequence[object]]

close()

Closes it.

Return type:

None

class schedr.connection_types.Generic(name, /, **values)

Bases: TwoWayConnection[dict[str, object], dict[str, object]]

Keys of one’s own: the task gets them as a dict.

with feature_flags() as flags: flags["region"], or async with.

Parameters:
  • name (str)

  • values (object)

class schedr.connection_types.Mongo(name, /, *, uri, database, user=None, password=None, ca_cert=None, timeout=30.0)

Bases: TwoWayConnection[object, object]

A MongoDB database: a pymongo Database, its client closed when the block ends.

with orders_db() as db: db.orders.count_documents({}). TLS is used and verified unless the URI says tls=false (decision 189): against ca_cert, else the system’s CAs; the URI’s own TLS options (tlsAllowInvalidHostnames=true, …) as written.

Parameters:
  • name (str)

  • uri (str)

  • database (str)

  • user (str | None)

  • password (str | None)

  • ca_cert (str | None)

  • timeout (float)

class schedr.connection_types.SchedrApi(name, /, *, server, token=None, user=None, password=None)

Bases: Connection[object]

A schedr deployment’s REST API, over HTTP: a schedr.api.Client.

For another deployment, or this one as a user of its own: with other_schedr() as api: api.post_event(...). A task reaches its own deployment through schedr.api with no connection at all.

Parameters:
  • name (str)

  • server (str)

  • token (str | None)

  • user (str | None)

  • password (str | None)