Skip to main content

Python/Streamlit client for ANT-OS iframe communication

Project description

ant-connect-streamlit

Python bridge for building Streamlit apps that run inside ANT-OS. Provides typed access to host context, signals, notifications, toolbar control, and an authenticated HTTP proxy.

Install

pip install ant-connect-streamlit

Or with uv:

uv add ant-connect-streamlit

Quick start

import streamlit as st
import ant_connect_streamlit as ant

bridge = ant.connect()

if bridge.context is None:
    st.info("Waiting for ANT-OS context...")
    st.stop()

st.write(f"Hello {bridge.user.firstname}!")
st.write(f"Project: {bridge.project.name}")

Run with streamlit run app.py and load in ANT-OS via Developer mode at /developer/8501.

API

connect() -> AntConnect

Initialize the bridge. Call once at the top of your script. The instance is cached in st.session_state and reused across Streamlit reruns.

Context

bridge.context      # Full Context object (typed)
bridge.user         # User | None
bridge.project      # ProjectShort | None
bridge.task         # Task | None
bridge.dark_mode    # bool | None
bridge.context_changed  # True if context changed since last rerun
bridge.changed("project", "user")  # Check specific fields

Signals

Send signals to the ANT-OS host:

# Raw dict
bridge.send_signal({"navigate": {"to": "OS.dash"}})
bridge.send_signal({"notepad": {"action": "toggle"}})
bridge.send_signal({"overlay": {"action": True}})

# Navigate to app
bridge.send_signal({"navigate": {"to": {"app": {"id": "my-app-id"}}}})

# Typed Signal model
from ant_connect_streamlit import Signal
bridge.send_signal(Signal(navigate={"to": "OS.profile"}))

Notifications

bridge.notify("Saved!", type="success")
bridge.notify("Something went wrong", type="error")
bridge.notify("Check your input", type="warning")
bridge.notify("FYI: task updated", type="info")

Toolbar

bridge.set_toolbar(
    title="My App",
    subtitle="v1.0",
    loading=True,
    menu=[
        {"icon": "mdi-refresh", "title": "Refresh", "notify": "Refreshed!"},
        {"icon": "mdi-counter", "title": "Count", "action": "increment_title"},
    ],
)

HTTP proxy

Make authenticated requests through the host:

result = bridge.request("/api/projects").response({
    "type": ProjectShort,
    "onSuccess": lambda d: ...,
    "onError": lambda e: ...,
})

The host adds authentication headers automatically. Requests are cached per URL+params — call bridge.clear_request_cache() to re-fetch.

Service calls

Call host services directly:

data = bridge.call_service("tables", "getAll", [project_id])

Types

All models are auto-generated from the ANT-OS TypeScript types and ship as Pydantic v2 models:

from ant_connect_streamlit import (
    Context, User, License, ProjectShort, Task, Signal,
    RequestOptions, ResponseConfig, ToolbarMenuItem,
)

The package includes a py.typed marker for PEP 561 — IDEs get full autocomplete and type checking.

Requirements

  • Python >= 3.11
  • Streamlit >= 1.30.0
  • ANT-OS host (the app runs inside an ANT-OS iframe)

Architecture

ANT-OS host (Vue)
  ↕ Comlink over MessagePort
Bridge iframe (bundled JS)
  ↕ Streamlit component protocol
Your Python app

The bridge component is a Streamlit custom component that establishes a Comlink connection to the ANT-OS host. Context flows from host to Python, signals flow from Python to host, HTTP requests are proxied through the host's authenticated Axios instance.

Demo

See ant-connect-streamlit-demo for a full working example.

Development (maintainers)

Regenerate Python types

Models in models.py are auto-generated from the ANT-OS TypeScript source — do not edit by hand.

# from the ant-connect-ts package in the monorepo
cd ../ant-connect-ts && pnpm run generate:python-types

Rebuild the bridge JS

The bridge frontend (src/ant_connect_streamlit/_bridge/frontend/) bundles @antcde/connect-ts. The built output in dist/ is committed and shipped in the wheel, so rebuild it after any TS change:

cd src/ant_connect_streamlit/_bridge/frontend && npm run build

Build the package

uv build            # writes sdist + wheel to dist/

The wheel ships the bridge dist/ JS and py.typed; the frontend build tooling (node_modules, vite/ts config, TS sources) is excluded. Verify metadata renders correctly:

uvx twine check dist/*

Publish to PyPI

# optional: dry-run to TestPyPI first
uvx twine upload --repository testpypi dist/*

# real publish
uvx twine upload dist/*

Bump version in pyproject.toml before each release — PyPI rejects re-uploads of an existing version. Authenticate with a PyPI API token (username __token__), e.g. via ~/.pypirc or TWINE_USERNAME / TWINE_PASSWORD env vars.

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

ant_connect_streamlit-0.1.0.tar.gz (42.7 kB view details)

Uploaded Source

Built Distribution

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

ant_connect_streamlit-0.1.0-py3-none-any.whl (44.4 kB view details)

Uploaded Python 3

File details

Details for the file ant_connect_streamlit-0.1.0.tar.gz.

File metadata

  • Download URL: ant_connect_streamlit-0.1.0.tar.gz
  • Upload date:
  • Size: 42.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for ant_connect_streamlit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 35be6e09e9917dd3daf472e124aaa568255e10fe49a1fa4f39d19bf2113dc7c9
MD5 7c2e61b3324a863664dc667bef577856
BLAKE2b-256 803916c416a95e78b6e4033b968221d8d917aee06825baca5bc034d8d756ce73

See more details on using hashes here.

File details

Details for the file ant_connect_streamlit-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ant_connect_streamlit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b42c69c129f1e12d2a3554a46f44d9f07d2a1dac74328ba3010b508f4a6fbbcf
MD5 a9dc9e4659e2b59af08acc5f944f7e66
BLAKE2b-256 24ea814716b11941c3afbd884904ca430e2a46bf1b98168281ea9830ec32cc66

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