Skip to content

Initial OpenFaaS Python SDK#1

Draft
welteki wants to merge 2 commits intoopenfaas:masterfrom
welteki:initial-sdk
Draft

Initial OpenFaaS Python SDK#1
welteki wants to merge 2 commits intoopenfaas:masterfrom
welteki:initial-sdk

Conversation

@welteki
Copy link
Copy Markdown
Member

@welteki welteki commented Apr 22, 2026

Description

Implements the initial Python SDK for OpenFaaS.

Provides synchronous (Client) and asynchronous (AsyncClient) clients backed by httpx, covering the core OpenFaaS REST API:

  • System info
  • Namespaces (list, get, create, update, delete)
  • Functions (list, get, deploy, update, scale, delete)
  • Secrets (list, create, update, delete)
  • Logs (streaming via iterator / async iterator)

Pydantic v2 models are used for all request and response types. FAAS_DEBUG=1 enables request/response logging with auth headers redacted.

Authentication

All standard OpenFaaS auth strategies are included:

  • BasicAuth — HTTP Basic
  • TokenAuth — OpenFaaS IAM token exchange (RFC 8693); caches and auto-refreshes the gateway JWT with a 10-second expiry buffer matching the Go SDK
  • ServiceAccountTokenSource — Reads a Kubernetes projected service account token from disk, re-read on every call so token rotation is transparent
  • ClientCredentialsTokenSource — Fetches tokens from an external IdP via OAuth 2.0 client_credentials, with internal caching
  • ClientCredentialsAuth — Direct ClientAuth wrapper around any TokenSource
  • MemoryTokenCache — Thread-safe in-memory cache for per-function scoped tokens (used by get_function_token())

TokenAuth also implements the TokenSource protocol, enabling automatic wiring as function_token_source for per-function scoped token exchange.

Tests

92 tests covering models, all client endpoints, all auth strategies, token exchange (sync + async), and the memory token cache.

Motivation and Context

  • I have raised an issue to propose this change (required)

welteki added 2 commits April 22, 2026 19:41
… coverage

Synchronous client backed by requests.Session, covering the full OpenFaaS
REST API: system info, namespaces, functions (deploy/update/scale/delete),
secrets, and streaming logs.

- requests.Session transport with FAAS_DEBUG hook-based logging
- requests.auth.AuthBase auth classes: BasicAuth, TokenAuth,
  ClientCredentialsAuth
- OpenFaaS IAM: ServiceAccountTokenSource, ClientCredentialsTokenSource,
  exchange_id_token, MemoryTokenCache, get_function_token()
- Pydantic v2 models for all request and response types
- Tests use requests-mock

Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
- Add _parse_function_name_namespace helper to extract name/namespace
  from /function/<name>.<ns> and /async-function/<name>.<ns> paths
- Add _FunctionAuth(requests.auth.AuthBase) compound auth that applies
  gateway auth then overrides Authorization with a per-function Bearer token
- Add Client.invoke_function() supporting bytes/str payload, custom
  method/headers/query params, async invocation, callback URL, and
  use_function_auth for IAM-scoped per-function token exchange
- Add echo handler and 18 new tests covering all invoke_function params
- Update README with invoke_function API reference section

Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant