Skip to main content

Page analytics for Streamlit multi-app made easy!

Project description

Streamlit Fyr

Streamlit Fyr is a simple analytics package meant for being used as a "centralized" analytics platform for multi-app streamlit deployments.

This package takes inspiration from:

This package offers a simple SQLite backend to test out the capabilities of the package, but the central usage is to connect to an external PostgresSQL and connect multiple applications to a single DB in order to centralize page analytics.

Key features:

  • Cookie-based persistent visitor_id across sessions.
  • Per-event rows in a queryable relational DB.
  • Multi-app centralization via app_name column. One DB for all your Streamlit apps
  • Bundled Plotly dashboard page (make_dashboard_page)

Installation

pip install streamlit-fyr               # core: Tracker + SQLiteBackend + raw query()
pip install 'streamlit-fyr[dashboard]'  # adds plotly for make_dashboard_page
pip install 'streamlit-fyr[postgres]'   # adds psycopg driver for PostgresBackend
pip install 'streamlit-fyr[all]'        # everything

The core install only ships SQLAlchemy + pandas + Streamlit. plotly and psycopg are optional extras — install them only if you need the bundled dashboard or the Postgres backend.

Basic Usage

SQLite backend

To test the capabilities of this package we recommend using first SQLiteBackend. This backend will expect to receive a file name for the sqlite db file to be created. Alternatively you can set the envrionmental variable ST_FYR_SQLITE_FILE to your db file.

import streamlit as st

from constants import DATA_PATH
from streamlit_fyr.dashboard import make_dashboard_page
from streamlit_fyr import SQLiteBackend, Tracker

backend = SQLiteBackend("telemetry.db")
tracker = Tracker(app_name="my_st_app", backend=backend)

tracker.init()

def my_page() -> None:
    """Render a new page."""
    tracker.page("my_page")
    st.title("My streamlit Page!")
    count = 0
    if st.button("click me!"):
        tracker.event("button_pressed", {"press_count": count})
        count += 1

...

page_telemetry = st.Page(
    make_dashboard_page(backend),
    title="Telemetry",
    icon=":material/analytics:",
)

pg = st.navigation({
        "App": [my_page],
        "Page Analytics": [page_telemetry],
    })
pg.run()

Postgres backend

To enable the postgres backend you must change backend to the PostgresBackend and add your DB connection string. Alternatively you can set the environment variable ST_FYR_CONNECTION_STRING to your connection string and the backend will read that value.

from streamlit_fyr import PostgresBackend, Tracker

backend = PostgresBackend(connection_string="postgresql+psycopg://...")
tracker = Tracker(app_name="my_st_app", backend=backend)

## Same config as with SQLite

Identifying authenticated users

If your app has authentication, call tracker.identify() after login resolves to attach a known identity to all subsequent events in the session:

user = get_logged_in_user()  # your auth layer
tracker.identify(user.id)

identify() stores the value in Streamlit session state and writes it to every event from that point forward alongside visitor_id. Events fired before identify() is called (e.g. the login page itself) will have user_id = NULL.

[!IMPORTANT] Privacy note: user_id is stored as plain text in the events table. Prefer an opaque internal ID over an email address or display name. If you do store PII, ensure your database access controls and data retention policy reflect that obligation.

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

streamlit_fyr-0.2.0.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

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

streamlit_fyr-0.2.0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file streamlit_fyr-0.2.0.tar.gz.

File metadata

  • Download URL: streamlit_fyr-0.2.0.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for streamlit_fyr-0.2.0.tar.gz
Algorithm Hash digest
SHA256 48c3d7fb6eb1198e8906d82a050b69582834f3299adb15f804f81ef48caf1129
MD5 e9c22b953ae5192ce225d11dead87933
BLAKE2b-256 33ce06321f569f1d216dd33019b128cc519b8c7f43c03f64f480d0d6d766df4b

See more details on using hashes here.

Provenance

The following attestation bundles were made for streamlit_fyr-0.2.0.tar.gz:

Publisher: release.yml on napelli91/streamlit-fyr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file streamlit_fyr-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: streamlit_fyr-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for streamlit_fyr-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 08ac1edf01487b692cba39ca3b6debe63367e572ee2b178f12c726193450cd80
MD5 d5432ac9752016cc034765f76b6b7124
BLAKE2b-256 c0bac4f0cba5c1ba2624c6677238019dc3f2ed2918591ed8416b9149003c76fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for streamlit_fyr-0.2.0-py3-none-any.whl:

Publisher: release.yml on napelli91/streamlit-fyr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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