Skip to main content

Restack AI library

Project description

Restack AI libraries

This is the Python Restack AI libraries.

Installation

You can install the Restack AI libraries using pip:

Using pip

pip install restack_ai

Using Poetry

poetry add restack_ai

Using uv

uv add restack_ai

Prerequisites

  • Python 3.8 or higher
  • Poetry (for dependency management)

Usage

To use the libraries in your project, you can import it like this:

from restack_ai import Restack

Initialize the Restack client

client = Restack()

Hide sensitive fields from the workflow UI

Wrap any value with Sensitive to opt it into selective field encryption. Only the marked fields are encrypted on the wire, so the engine UI keeps showing useful debug context (email, ids, timestamps) while sensitive values render as opaque ciphertext.

Engine-managed key (recommended)

When the engine is configured with RESTACK_ENGINE_PAYLOAD_KEY and RESTACK_API_BEARER_TOKEN (see the engine readme), the SDK auto-fetches the key during connect() and wires up the codec for you. Consumer services don't need any new env:

from pydantic import BaseModel
from restack_ai import Restack, Sensitive


class SignupInput(BaseModel):
    email: str
    password: Sensitive[str]


client = Restack()  # engine config from RESTACK_ENGINE_* envs

# Caller side:
await client.schedule_workflow(
    workflow_name="UserSignupWorkflow",
    workflow_id=workflow_id,
    workflow_input=SignupInput(
        email=email,
        password=Sensitive(value=password),
    ).model_dump(),
)


# Workflow side: receive the typed input, unwrap when you need plaintext.
@workflow.defn
class UserSignupWorkflow:
    @workflow.run
    async def run(self, payload: SignupInput) -> None:
        raw_password = payload.password.unwrap()
        ...

The SDK passes its api_key as the bearer token when fetching the key. Engines that don't expose the key endpoint (older versions, or with the env unset) cause the SDK to silently fall back to no encryption — no deployment breakage.

In the engine UI the password field renders as {"__restack_encrypted__": "v1", "alg": "AES-256-GCM", "iv": "...", "ct": "..."} instead of plaintext.

create_aes_gcm_encryption (used internally) requires the optional cryptography package — install it on every service that runs as a Restack worker so it can decrypt: pip install cryptography.

Consumer-managed key (advanced)

To keep the key entirely out of the engine — e.g. each consumer service manages its own key in a KMS — pass a codec explicitly. This overrides the engine auto-wire:

import os
from restack_ai import (
    Restack,
    SensitiveFieldsCodec,
    create_aes_gcm_encryption,
)
from restack_ai.restack import CloudConnectionOptions

key = os.urandom(32)  # load from your secrets store in real code
codec = SensitiveFieldsCodec(create_aes_gcm_encryption(key))

client = Restack(
    CloudConnectionOptions(
        engine_id=..., api_key=...,
        payload_codecs=[codec],
    ),
)

For non-AES backends (KMS, HSM, envelope encryption) provide your own implementation of SensitiveEncryption and pass it to SensitiveFieldsCodec.

Documentation

For detailed usage instructions, please visit our examples repository at https://github.com/restackio/examples-python.

Development

If you want to contribute to the libraries development:

Clone the repository and navigate to the engine/libraries/python directory.

Install Poetry/uv if you haven't already: https://python-poetry.org/docs/#installation or use pip

Activate the virtual environment:

If using uv:

uv venv && source .venv/bin/activate

If using poetry:

poetry env use 3.12 && poetry shell

If using pip:

python -m venv .venv && source .venv/bin/activate

Install the project dependencies:

If using uv:

uv sync

If using Poetry:

poetry install

If using pip:

pip install -e .

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

restack_ai-0.0.121.tar.gz (31.1 kB view details)

Uploaded Source

Built Distribution

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

restack_ai-0.0.121-py3-none-any.whl (37.6 kB view details)

Uploaded Python 3

File details

Details for the file restack_ai-0.0.121.tar.gz.

File metadata

  • Download URL: restack_ai-0.0.121.tar.gz
  • Upload date:
  • Size: 31.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for restack_ai-0.0.121.tar.gz
Algorithm Hash digest
SHA256 00b61d7c3b2a720d98b7c1875edf582f1e3a8a652f311f1a4a6c96022efb1725
MD5 37c87c9ab360318e49607a4ed04430c7
BLAKE2b-256 ac6953c7309f82fbb6db7b9e65b7846df8a824bd6ec15f135a81a185544b2761

See more details on using hashes here.

File details

Details for the file restack_ai-0.0.121-py3-none-any.whl.

File metadata

  • Download URL: restack_ai-0.0.121-py3-none-any.whl
  • Upload date:
  • Size: 37.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for restack_ai-0.0.121-py3-none-any.whl
Algorithm Hash digest
SHA256 924a281e565ae666917a89ef27d9c9b12daf738a242d26587dcfe708642cc990
MD5 02430ce9d124cae389e8dda0e58695e9
BLAKE2b-256 d7dcad38ca171e23a1fb48eaf3ebd3fe9527098f3464382a1106d3497303b599

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