[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-posthog-writing-streamlit-apps":3,"mdc--pu7y6q-key":49,"related-repo-posthog-writing-streamlit-apps":880,"related-org-posthog-writing-streamlit-apps":984},{"slug":4,"name":4,"fn":5,"description":6,"org":7,"tags":11,"stars":23,"repoUrl":24,"updatedAt":25,"license":26,"forks":27,"topics":28,"repo":44,"sourceUrl":47,"mdContent":48},"writing-streamlit-apps","write Streamlit apps for PostHog","Write Streamlit app source code that runs well in a PostHog sandbox — the posthog_apps.query() bridge for reading PostHog data, the packages baked into the sandbox image, caching and session state across Streamlit reruns, layout and chart patterns, and single-file app.py structure. Use when authoring or debugging the Python source of a PostHog Streamlit app, when a query inside an app fails, or when asked to \"write a streamlit app that shows PostHog data\".",{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},"posthog","PostHog","https:\u002F\u002Fpexgzepcugksgbtrxkhf.supabase.co\u002Fstorage\u002Fv1\u002Fobject\u002Fpublic\u002Forg-logos\u002Fposthog.png",[12,14,17,20],{"name":9,"slug":8,"type":13},"tag",{"name":15,"slug":16,"type":13},"Data Analysis","data-analysis",{"name":18,"slug":19,"type":13},"Streamlit","streamlit",{"name":21,"slug":22,"type":13},"Engineering","engineering",35568,"https:\u002F\u002Fgithub.com\u002FPostHog\u002Fposthog","2026-07-31T06:23:36.250839",null,2977,[29,30,31,32,33,34,35,36,37,38,39,40,41,42,43],"ab-testing","ai-analytics","analytics","cdp","data-warehouse","experiments","feature-flags","javascript","product-analytics","python","react","session-replay","surveys","typescript","web-analytics",{"repoUrl":24,"stars":23,"forks":27,"topics":45,"description":46},[29,30,31,32,33,34,35,36,37,38,39,40,41,42,43],"🦔 PostHog is an all-in-one developer platform for building successful products. We offer product analytics, web analytics, session replay, error tracking, feature flags, experimentation, surveys, data warehouse, a CDP, and an AI product assistant to help debug your code, ship features faster, and keep all your usage and customer data in one stack.","https:\u002F\u002Fgithub.com\u002FPostHog\u002Fposthog\u002Ftree\u002FHEAD\u002Fproducts\u002Fstreamlit_apps\u002Fskills\u002Fwriting-streamlit-apps","---\nname: writing-streamlit-apps\ndescription: Write Streamlit app source code that runs well in a PostHog sandbox — the posthog_apps.query() bridge for reading PostHog data, the packages baked into the sandbox image, caching and session state across Streamlit reruns, layout and chart patterns, and single-file app.py structure. Use when authoring or debugging the Python source of a PostHog Streamlit app, when a query inside an app fails, or when asked to \"write a streamlit app that shows PostHog data\".\n---\n\n# Writing Streamlit apps for the PostHog sandbox\n\nThe source you write becomes `app.py` at the root of a sandboxed Streamlit 1.31 runtime.\nDeployment mechanics (create\u002Fstart\u002Fshare) are the `managing-streamlit-apps` skill; this one is about the code.\n\n## Reading PostHog data: `posthog_apps.query()`\n\nThe one and only data door is the in-sandbox bridge:\n\n```python\nimport posthog_apps\n\ndf = posthog_apps.query(\"SELECT event, count() FROM events GROUP BY event LIMIT 10\")\n```\n\n- Takes a HogQL string, returns a **pandas DataFrame**.\n- Raises `RuntimeError` on failure. The message is deliberately generic (\"Query execution failed\") — the bridge does not return query internals to the sandbox, so you cannot diagnose a bad query from inside the app. Catch it and render with `st.error(str(e))` so viewers get a message instead of a stack trace, and test queries in the SQL editor where real errors are visible.\n- `import posthog` does NOT exist in the sandbox — the module is `posthog_apps`, deliberately distinct from the posthog-python SDK's name.\n- The bridge is pre-authenticated to the app's project; user code never sees a token, and there is nothing to configure.\n- Queries run with server-side caps (30 s execution, 256 MB memory) that don't scale with sandbox sizing — so bound time ranges, `LIMIT` results, and aggregate in HogQL rather than pulling raw events into pandas.\n\n## Design for Streamlit's rerun model\n\nStreamlit reruns the whole script top to bottom on every widget interaction.\nTwo consequences:\n\n1. **Cache every bridge call** — uncached, one slider drag re-fires every query:\n\n   ```python\n   @st.cache_data(ttl=300, show_spinner=\"Running query...\")\n   def run_query(hogql: str) -> pd.DataFrame:\n       return posthog_apps.query(hogql)\n   ```\n\n2. **Use `st.session_state` for anything that must survive reruns** — accumulated selections, pagination cursors, \"last refreshed\" stamps. Module-level variables reset on every interaction.\n\nWidgets drive parameters naturally, but **never interpolate a free-text widget value into HogQL**.\nThe bridge runs your query with the version author's data access, and anyone who can view the app drives those widgets — a raw `st.text_input` spliced into a query hands viewers the author's access to write their own.\nConstrain the input instead: pick from a fixed list you control (`st.selectbox` over known values), or coerce to a type that can't carry SQL (`int(days)`, a `date` from `st.date_input`), and validate before it reaches the query.\n\n## Layout and charts\n\n- `st.set_page_config(page_title=..., layout=\"wide\")` first — the default narrow layout wastes most of the screen for data apps.\n- Structure with `st.columns` for side-by-side metrics, `st.tabs` for alternate views, `st.expander` for detail sections; `st.metric` for headline numbers.\n- Charts: `st.plotly_chart(fig, use_container_width=True)` with plotly express is the reliable default; `st.dataframe(df, use_container_width=True)` for tables. matplotlib\u002Fseaborn also work via `st.pyplot`.\n\n## What's installed\n\nThe image ships Python 3.11 with: `streamlit` 1.31, `pandas`, `numpy`, `polars`, `plotly`, `matplotlib`, `seaborn`, `scipy`, `scikit-learn`, `pyarrow`, `duckdb`, `requests`, `beautifulsoup4`, `lxml`, `sqlalchemy`, `aiohttp`.\nThere is no way to add dependencies: the sandbox never runs pip (a deliberate security posture — no arbitrary package code at boot), and a `requirements.txt` in an uploaded zip is tolerated but dropped. Only import what's listed above.\n\n## Structure and runtime constraints\n\n- **One file.** Via the MCP set-source flow your source IS `app.py`; there are no other modules, so keep everything in it.\n- The sandbox is ephemeral: anything written to disk disappears on stop\u002Frestart. Don't build state on files; recompute from queries (with caching) or hold it in `st.session_state`.\n- Your code runs as an unprivileged user; there's no posthog SDK, no way to pass your own environment variables or secrets to the app, and no expectation of general network egress. Don't read from `os.environ` — anything there belongs to the sandbox runtime, not your app. Design around `posthog_apps.query()` as the data source.\n\n## A minimal well-shaped app\n\n```python\nimport pandas as pd\nimport plotly.express as px\nimport posthog_apps\nimport streamlit as st\n\nst.set_page_config(page_title=\"Events overview\", layout=\"wide\")\nst.title(\"Events overview\")\n\n\n@st.cache_data(ttl=300, show_spinner=\"Running query...\")\ndef run_query(hogql: str) -> pd.DataFrame:\n    return posthog_apps.query(hogql)\n\n\n# A slider is bounded and coerced to int, so it is safe to interpolate.\ndays = int(st.slider(\"Days to show\", 1, 30, 7))\ntry:\n    daily = run_query(\n        f\"\"\"\n        SELECT toDate(timestamp) AS day, count() AS events\n        FROM events\n        WHERE timestamp >= now() - INTERVAL {days} DAY\n        GROUP BY day ORDER BY day\n        \"\"\"\n    )\n    st.plotly_chart(px.bar(daily, x=\"day\", y=\"events\"), use_container_width=True)\nexcept RuntimeError as e:\n    st.error(str(e))\n```\n",{"data":50,"body":51},{"name":4,"description":6},{"type":52,"children":53},"root",[54,63,86,99,104,144,220,226,231,294,346,352,431,437,564,570,621,627,874],{"type":55,"tag":56,"props":57,"children":59},"element","h1",{"id":58},"writing-streamlit-apps-for-the-posthog-sandbox",[60],{"type":61,"value":62},"text","Writing Streamlit apps for the PostHog sandbox",{"type":55,"tag":64,"props":65,"children":66},"p",{},[67,69,76,78,84],{"type":61,"value":68},"The source you write becomes ",{"type":55,"tag":70,"props":71,"children":73},"code",{"className":72},[],[74],{"type":61,"value":75},"app.py",{"type":61,"value":77}," at the root of a sandboxed Streamlit 1.31 runtime.\nDeployment mechanics (create\u002Fstart\u002Fshare) are the ",{"type":55,"tag":70,"props":79,"children":81},{"className":80},[],[82],{"type":61,"value":83},"managing-streamlit-apps",{"type":61,"value":85}," skill; this one is about the code.",{"type":55,"tag":87,"props":88,"children":90},"h2",{"id":89},"reading-posthog-data-posthog_appsquery",[91,93],{"type":61,"value":92},"Reading PostHog data: ",{"type":55,"tag":70,"props":94,"children":96},{"className":95},[],[97],{"type":61,"value":98},"posthog_apps.query()",{"type":55,"tag":64,"props":100,"children":101},{},[102],{"type":61,"value":103},"The one and only data door is the in-sandbox bridge:",{"type":55,"tag":105,"props":106,"children":110},"pre",{"className":107,"code":108,"language":38,"meta":109,"style":109},"language-python shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","import posthog_apps\n\ndf = posthog_apps.query(\"SELECT event, count() FROM events GROUP BY event LIMIT 10\")\n","",[111],{"type":55,"tag":70,"props":112,"children":113},{"__ignoreMap":109},[114,125,135],{"type":55,"tag":115,"props":116,"children":119},"span",{"class":117,"line":118},"line",1,[120],{"type":55,"tag":115,"props":121,"children":122},{},[123],{"type":61,"value":124},"import posthog_apps\n",{"type":55,"tag":115,"props":126,"children":128},{"class":117,"line":127},2,[129],{"type":55,"tag":115,"props":130,"children":132},{"emptyLinePlaceholder":131},true,[133],{"type":61,"value":134},"\n",{"type":55,"tag":115,"props":136,"children":138},{"class":117,"line":137},3,[139],{"type":55,"tag":115,"props":140,"children":141},{},[142],{"type":61,"value":143},"df = posthog_apps.query(\"SELECT event, count() FROM events GROUP BY event LIMIT 10\")\n",{"type":55,"tag":145,"props":146,"children":147},"ul",{},[148,162,183,202,207],{"type":55,"tag":149,"props":150,"children":151},"li",{},[152,154,160],{"type":61,"value":153},"Takes a HogQL string, returns a ",{"type":55,"tag":155,"props":156,"children":157},"strong",{},[158],{"type":61,"value":159},"pandas DataFrame",{"type":61,"value":161},".",{"type":55,"tag":149,"props":163,"children":164},{},[165,167,173,175,181],{"type":61,"value":166},"Raises ",{"type":55,"tag":70,"props":168,"children":170},{"className":169},[],[171],{"type":61,"value":172},"RuntimeError",{"type":61,"value":174}," on failure. The message is deliberately generic (\"Query execution failed\") — the bridge does not return query internals to the sandbox, so you cannot diagnose a bad query from inside the app. Catch it and render with ",{"type":55,"tag":70,"props":176,"children":178},{"className":177},[],[179],{"type":61,"value":180},"st.error(str(e))",{"type":61,"value":182}," so viewers get a message instead of a stack trace, and test queries in the SQL editor where real errors are visible.",{"type":55,"tag":149,"props":184,"children":185},{},[186,192,194,200],{"type":55,"tag":70,"props":187,"children":189},{"className":188},[],[190],{"type":61,"value":191},"import posthog",{"type":61,"value":193}," does NOT exist in the sandbox — the module is ",{"type":55,"tag":70,"props":195,"children":197},{"className":196},[],[198],{"type":61,"value":199},"posthog_apps",{"type":61,"value":201},", deliberately distinct from the posthog-python SDK's name.",{"type":55,"tag":149,"props":203,"children":204},{},[205],{"type":61,"value":206},"The bridge is pre-authenticated to the app's project; user code never sees a token, and there is nothing to configure.",{"type":55,"tag":149,"props":208,"children":209},{},[210,212,218],{"type":61,"value":211},"Queries run with server-side caps (30 s execution, 256 MB memory) that don't scale with sandbox sizing — so bound time ranges, ",{"type":55,"tag":70,"props":213,"children":215},{"className":214},[],[216],{"type":61,"value":217},"LIMIT",{"type":61,"value":219}," results, and aggregate in HogQL rather than pulling raw events into pandas.",{"type":55,"tag":87,"props":221,"children":223},{"id":222},"design-for-streamlits-rerun-model",[224],{"type":61,"value":225},"Design for Streamlit's rerun model",{"type":55,"tag":64,"props":227,"children":228},{},[229],{"type":61,"value":230},"Streamlit reruns the whole script top to bottom on every widget interaction.\nTwo consequences:",{"type":55,"tag":232,"props":233,"children":234},"ol",{},[235,276],{"type":55,"tag":149,"props":236,"children":237},{},[238,243,245],{"type":55,"tag":155,"props":239,"children":240},{},[241],{"type":61,"value":242},"Cache every bridge call",{"type":61,"value":244}," — uncached, one slider drag re-fires every query:",{"type":55,"tag":105,"props":246,"children":248},{"className":107,"code":247,"language":38,"meta":109,"style":109},"@st.cache_data(ttl=300, show_spinner=\"Running query...\")\ndef run_query(hogql: str) -> pd.DataFrame:\n    return posthog_apps.query(hogql)\n",[249],{"type":55,"tag":70,"props":250,"children":251},{"__ignoreMap":109},[252,260,268],{"type":55,"tag":115,"props":253,"children":254},{"class":117,"line":118},[255],{"type":55,"tag":115,"props":256,"children":257},{},[258],{"type":61,"value":259},"@st.cache_data(ttl=300, show_spinner=\"Running query...\")\n",{"type":55,"tag":115,"props":261,"children":262},{"class":117,"line":127},[263],{"type":55,"tag":115,"props":264,"children":265},{},[266],{"type":61,"value":267},"def run_query(hogql: str) -> pd.DataFrame:\n",{"type":55,"tag":115,"props":269,"children":270},{"class":117,"line":137},[271],{"type":55,"tag":115,"props":272,"children":273},{},[274],{"type":61,"value":275},"    return posthog_apps.query(hogql)\n",{"type":55,"tag":149,"props":277,"children":278},{},[279,292],{"type":55,"tag":155,"props":280,"children":281},{},[282,284,290],{"type":61,"value":283},"Use ",{"type":55,"tag":70,"props":285,"children":287},{"className":286},[],[288],{"type":61,"value":289},"st.session_state",{"type":61,"value":291}," for anything that must survive reruns",{"type":61,"value":293}," — accumulated selections, pagination cursors, \"last refreshed\" stamps. Module-level variables reset on every interaction.",{"type":55,"tag":64,"props":295,"children":296},{},[297,299,304,306,312,314,320,322,328,330,336,338,344],{"type":61,"value":298},"Widgets drive parameters naturally, but ",{"type":55,"tag":155,"props":300,"children":301},{},[302],{"type":61,"value":303},"never interpolate a free-text widget value into HogQL",{"type":61,"value":305},".\nThe bridge runs your query with the version author's data access, and anyone who can view the app drives those widgets — a raw ",{"type":55,"tag":70,"props":307,"children":309},{"className":308},[],[310],{"type":61,"value":311},"st.text_input",{"type":61,"value":313}," spliced into a query hands viewers the author's access to write their own.\nConstrain the input instead: pick from a fixed list you control (",{"type":55,"tag":70,"props":315,"children":317},{"className":316},[],[318],{"type":61,"value":319},"st.selectbox",{"type":61,"value":321}," over known values), or coerce to a type that can't carry SQL (",{"type":55,"tag":70,"props":323,"children":325},{"className":324},[],[326],{"type":61,"value":327},"int(days)",{"type":61,"value":329},", a ",{"type":55,"tag":70,"props":331,"children":333},{"className":332},[],[334],{"type":61,"value":335},"date",{"type":61,"value":337}," from ",{"type":55,"tag":70,"props":339,"children":341},{"className":340},[],[342],{"type":61,"value":343},"st.date_input",{"type":61,"value":345},"), and validate before it reaches the query.",{"type":55,"tag":87,"props":347,"children":349},{"id":348},"layout-and-charts",[350],{"type":61,"value":351},"Layout and charts",{"type":55,"tag":145,"props":353,"children":354},{},[355,366,403],{"type":55,"tag":149,"props":356,"children":357},{},[358,364],{"type":55,"tag":70,"props":359,"children":361},{"className":360},[],[362],{"type":61,"value":363},"st.set_page_config(page_title=..., layout=\"wide\")",{"type":61,"value":365}," first — the default narrow layout wastes most of the screen for data apps.",{"type":55,"tag":149,"props":367,"children":368},{},[369,371,377,379,385,387,393,395,401],{"type":61,"value":370},"Structure with ",{"type":55,"tag":70,"props":372,"children":374},{"className":373},[],[375],{"type":61,"value":376},"st.columns",{"type":61,"value":378}," for side-by-side metrics, ",{"type":55,"tag":70,"props":380,"children":382},{"className":381},[],[383],{"type":61,"value":384},"st.tabs",{"type":61,"value":386}," for alternate views, ",{"type":55,"tag":70,"props":388,"children":390},{"className":389},[],[391],{"type":61,"value":392},"st.expander",{"type":61,"value":394}," for detail sections; ",{"type":55,"tag":70,"props":396,"children":398},{"className":397},[],[399],{"type":61,"value":400},"st.metric",{"type":61,"value":402}," for headline numbers.",{"type":55,"tag":149,"props":404,"children":405},{},[406,408,414,416,422,424,430],{"type":61,"value":407},"Charts: ",{"type":55,"tag":70,"props":409,"children":411},{"className":410},[],[412],{"type":61,"value":413},"st.plotly_chart(fig, use_container_width=True)",{"type":61,"value":415}," with plotly express is the reliable default; ",{"type":55,"tag":70,"props":417,"children":419},{"className":418},[],[420],{"type":61,"value":421},"st.dataframe(df, use_container_width=True)",{"type":61,"value":423}," for tables. matplotlib\u002Fseaborn also work via ",{"type":55,"tag":70,"props":425,"children":427},{"className":426},[],[428],{"type":61,"value":429},"st.pyplot",{"type":61,"value":161},{"type":55,"tag":87,"props":432,"children":434},{"id":433},"whats-installed",[435],{"type":61,"value":436},"What's installed",{"type":55,"tag":64,"props":438,"children":439},{},[440,442,447,449,455,457,463,464,470,471,477,478,484,485,491,492,498,499,505,506,512,513,519,520,526,527,533,534,540,541,547,548,554,556,562],{"type":61,"value":441},"The image ships Python 3.11 with: ",{"type":55,"tag":70,"props":443,"children":445},{"className":444},[],[446],{"type":61,"value":19},{"type":61,"value":448}," 1.31, ",{"type":55,"tag":70,"props":450,"children":452},{"className":451},[],[453],{"type":61,"value":454},"pandas",{"type":61,"value":456},", ",{"type":55,"tag":70,"props":458,"children":460},{"className":459},[],[461],{"type":61,"value":462},"numpy",{"type":61,"value":456},{"type":55,"tag":70,"props":465,"children":467},{"className":466},[],[468],{"type":61,"value":469},"polars",{"type":61,"value":456},{"type":55,"tag":70,"props":472,"children":474},{"className":473},[],[475],{"type":61,"value":476},"plotly",{"type":61,"value":456},{"type":55,"tag":70,"props":479,"children":481},{"className":480},[],[482],{"type":61,"value":483},"matplotlib",{"type":61,"value":456},{"type":55,"tag":70,"props":486,"children":488},{"className":487},[],[489],{"type":61,"value":490},"seaborn",{"type":61,"value":456},{"type":55,"tag":70,"props":493,"children":495},{"className":494},[],[496],{"type":61,"value":497},"scipy",{"type":61,"value":456},{"type":55,"tag":70,"props":500,"children":502},{"className":501},[],[503],{"type":61,"value":504},"scikit-learn",{"type":61,"value":456},{"type":55,"tag":70,"props":507,"children":509},{"className":508},[],[510],{"type":61,"value":511},"pyarrow",{"type":61,"value":456},{"type":55,"tag":70,"props":514,"children":516},{"className":515},[],[517],{"type":61,"value":518},"duckdb",{"type":61,"value":456},{"type":55,"tag":70,"props":521,"children":523},{"className":522},[],[524],{"type":61,"value":525},"requests",{"type":61,"value":456},{"type":55,"tag":70,"props":528,"children":530},{"className":529},[],[531],{"type":61,"value":532},"beautifulsoup4",{"type":61,"value":456},{"type":55,"tag":70,"props":535,"children":537},{"className":536},[],[538],{"type":61,"value":539},"lxml",{"type":61,"value":456},{"type":55,"tag":70,"props":542,"children":544},{"className":543},[],[545],{"type":61,"value":546},"sqlalchemy",{"type":61,"value":456},{"type":55,"tag":70,"props":549,"children":551},{"className":550},[],[552],{"type":61,"value":553},"aiohttp",{"type":61,"value":555},".\nThere is no way to add dependencies: the sandbox never runs pip (a deliberate security posture — no arbitrary package code at boot), and a ",{"type":55,"tag":70,"props":557,"children":559},{"className":558},[],[560],{"type":61,"value":561},"requirements.txt",{"type":61,"value":563}," in an uploaded zip is tolerated but dropped. Only import what's listed above.",{"type":55,"tag":87,"props":565,"children":567},{"id":566},"structure-and-runtime-constraints",[568],{"type":61,"value":569},"Structure and runtime constraints",{"type":55,"tag":145,"props":571,"children":572},{},[573,590,601],{"type":55,"tag":149,"props":574,"children":575},{},[576,581,583,588],{"type":55,"tag":155,"props":577,"children":578},{},[579],{"type":61,"value":580},"One file.",{"type":61,"value":582}," Via the MCP set-source flow your source IS ",{"type":55,"tag":70,"props":584,"children":586},{"className":585},[],[587],{"type":61,"value":75},{"type":61,"value":589},"; there are no other modules, so keep everything in it.",{"type":55,"tag":149,"props":591,"children":592},{},[593,595,600],{"type":61,"value":594},"The sandbox is ephemeral: anything written to disk disappears on stop\u002Frestart. Don't build state on files; recompute from queries (with caching) or hold it in ",{"type":55,"tag":70,"props":596,"children":598},{"className":597},[],[599],{"type":61,"value":289},{"type":61,"value":161},{"type":55,"tag":149,"props":602,"children":603},{},[604,606,612,614,619],{"type":61,"value":605},"Your code runs as an unprivileged user; there's no posthog SDK, no way to pass your own environment variables or secrets to the app, and no expectation of general network egress. Don't read from ",{"type":55,"tag":70,"props":607,"children":609},{"className":608},[],[610],{"type":61,"value":611},"os.environ",{"type":61,"value":613}," — anything there belongs to the sandbox runtime, not your app. Design around ",{"type":55,"tag":70,"props":615,"children":617},{"className":616},[],[618],{"type":61,"value":98},{"type":61,"value":620}," as the data source.",{"type":55,"tag":87,"props":622,"children":624},{"id":623},"a-minimal-well-shaped-app",[625],{"type":61,"value":626},"A minimal well-shaped app",{"type":55,"tag":105,"props":628,"children":630},{"className":107,"code":629,"language":38,"meta":109,"style":109},"import pandas as pd\nimport plotly.express as px\nimport posthog_apps\nimport streamlit as st\n\nst.set_page_config(page_title=\"Events overview\", layout=\"wide\")\nst.title(\"Events overview\")\n\n\n@st.cache_data(ttl=300, show_spinner=\"Running query...\")\ndef run_query(hogql: str) -> pd.DataFrame:\n    return posthog_apps.query(hogql)\n\n\n# A slider is bounded and coerced to int, so it is safe to interpolate.\ndays = int(st.slider(\"Days to show\", 1, 30, 7))\ntry:\n    daily = run_query(\n        f\"\"\"\n        SELECT toDate(timestamp) AS day, count() AS events\n        FROM events\n        WHERE timestamp >= now() - INTERVAL {days} DAY\n        GROUP BY day ORDER BY day\n        \"\"\"\n    )\n    st.plotly_chart(px.bar(daily, x=\"day\", y=\"events\"), use_container_width=True)\nexcept RuntimeError as e:\n    st.error(str(e))\n",[631],{"type":55,"tag":70,"props":632,"children":633},{"__ignoreMap":109},[634,642,650,657,666,674,683,692,700,708,716,724,732,740,748,757,766,775,784,793,802,811,820,829,838,847,856,865],{"type":55,"tag":115,"props":635,"children":636},{"class":117,"line":118},[637],{"type":55,"tag":115,"props":638,"children":639},{},[640],{"type":61,"value":641},"import pandas as pd\n",{"type":55,"tag":115,"props":643,"children":644},{"class":117,"line":127},[645],{"type":55,"tag":115,"props":646,"children":647},{},[648],{"type":61,"value":649},"import plotly.express as px\n",{"type":55,"tag":115,"props":651,"children":652},{"class":117,"line":137},[653],{"type":55,"tag":115,"props":654,"children":655},{},[656],{"type":61,"value":124},{"type":55,"tag":115,"props":658,"children":660},{"class":117,"line":659},4,[661],{"type":55,"tag":115,"props":662,"children":663},{},[664],{"type":61,"value":665},"import streamlit as st\n",{"type":55,"tag":115,"props":667,"children":669},{"class":117,"line":668},5,[670],{"type":55,"tag":115,"props":671,"children":672},{"emptyLinePlaceholder":131},[673],{"type":61,"value":134},{"type":55,"tag":115,"props":675,"children":677},{"class":117,"line":676},6,[678],{"type":55,"tag":115,"props":679,"children":680},{},[681],{"type":61,"value":682},"st.set_page_config(page_title=\"Events overview\", layout=\"wide\")\n",{"type":55,"tag":115,"props":684,"children":686},{"class":117,"line":685},7,[687],{"type":55,"tag":115,"props":688,"children":689},{},[690],{"type":61,"value":691},"st.title(\"Events overview\")\n",{"type":55,"tag":115,"props":693,"children":695},{"class":117,"line":694},8,[696],{"type":55,"tag":115,"props":697,"children":698},{"emptyLinePlaceholder":131},[699],{"type":61,"value":134},{"type":55,"tag":115,"props":701,"children":703},{"class":117,"line":702},9,[704],{"type":55,"tag":115,"props":705,"children":706},{"emptyLinePlaceholder":131},[707],{"type":61,"value":134},{"type":55,"tag":115,"props":709,"children":711},{"class":117,"line":710},10,[712],{"type":55,"tag":115,"props":713,"children":714},{},[715],{"type":61,"value":259},{"type":55,"tag":115,"props":717,"children":719},{"class":117,"line":718},11,[720],{"type":55,"tag":115,"props":721,"children":722},{},[723],{"type":61,"value":267},{"type":55,"tag":115,"props":725,"children":727},{"class":117,"line":726},12,[728],{"type":55,"tag":115,"props":729,"children":730},{},[731],{"type":61,"value":275},{"type":55,"tag":115,"props":733,"children":735},{"class":117,"line":734},13,[736],{"type":55,"tag":115,"props":737,"children":738},{"emptyLinePlaceholder":131},[739],{"type":61,"value":134},{"type":55,"tag":115,"props":741,"children":743},{"class":117,"line":742},14,[744],{"type":55,"tag":115,"props":745,"children":746},{"emptyLinePlaceholder":131},[747],{"type":61,"value":134},{"type":55,"tag":115,"props":749,"children":751},{"class":117,"line":750},15,[752],{"type":55,"tag":115,"props":753,"children":754},{},[755],{"type":61,"value":756},"# A slider is bounded and coerced to int, so it is safe to interpolate.\n",{"type":55,"tag":115,"props":758,"children":760},{"class":117,"line":759},16,[761],{"type":55,"tag":115,"props":762,"children":763},{},[764],{"type":61,"value":765},"days = int(st.slider(\"Days to show\", 1, 30, 7))\n",{"type":55,"tag":115,"props":767,"children":769},{"class":117,"line":768},17,[770],{"type":55,"tag":115,"props":771,"children":772},{},[773],{"type":61,"value":774},"try:\n",{"type":55,"tag":115,"props":776,"children":778},{"class":117,"line":777},18,[779],{"type":55,"tag":115,"props":780,"children":781},{},[782],{"type":61,"value":783},"    daily = run_query(\n",{"type":55,"tag":115,"props":785,"children":787},{"class":117,"line":786},19,[788],{"type":55,"tag":115,"props":789,"children":790},{},[791],{"type":61,"value":792},"        f\"\"\"\n",{"type":55,"tag":115,"props":794,"children":796},{"class":117,"line":795},20,[797],{"type":55,"tag":115,"props":798,"children":799},{},[800],{"type":61,"value":801},"        SELECT toDate(timestamp) AS day, count() AS events\n",{"type":55,"tag":115,"props":803,"children":805},{"class":117,"line":804},21,[806],{"type":55,"tag":115,"props":807,"children":808},{},[809],{"type":61,"value":810},"        FROM events\n",{"type":55,"tag":115,"props":812,"children":814},{"class":117,"line":813},22,[815],{"type":55,"tag":115,"props":816,"children":817},{},[818],{"type":61,"value":819},"        WHERE timestamp >= now() - INTERVAL {days} DAY\n",{"type":55,"tag":115,"props":821,"children":823},{"class":117,"line":822},23,[824],{"type":55,"tag":115,"props":825,"children":826},{},[827],{"type":61,"value":828},"        GROUP BY day ORDER BY day\n",{"type":55,"tag":115,"props":830,"children":832},{"class":117,"line":831},24,[833],{"type":55,"tag":115,"props":834,"children":835},{},[836],{"type":61,"value":837},"        \"\"\"\n",{"type":55,"tag":115,"props":839,"children":841},{"class":117,"line":840},25,[842],{"type":55,"tag":115,"props":843,"children":844},{},[845],{"type":61,"value":846},"    )\n",{"type":55,"tag":115,"props":848,"children":850},{"class":117,"line":849},26,[851],{"type":55,"tag":115,"props":852,"children":853},{},[854],{"type":61,"value":855},"    st.plotly_chart(px.bar(daily, x=\"day\", y=\"events\"), use_container_width=True)\n",{"type":55,"tag":115,"props":857,"children":859},{"class":117,"line":858},27,[860],{"type":55,"tag":115,"props":861,"children":862},{},[863],{"type":61,"value":864},"except RuntimeError as e:\n",{"type":55,"tag":115,"props":866,"children":868},{"class":117,"line":867},28,[869],{"type":55,"tag":115,"props":870,"children":871},{},[872],{"type":61,"value":873},"    st.error(str(e))\n",{"type":55,"tag":875,"props":876,"children":877},"style",{},[878],{"type":61,"value":879},"html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"items":881,"total":983},[882,898,910,922,935,950,966],{"slug":883,"name":883,"fn":884,"description":885,"org":886,"tags":887,"stars":23,"repoUrl":24,"updatedAt":897},"analyzing-expensive-users","analyze expensive users in AI observability","Analyze the most expensive users in AI observability and explain why they cost so much. Use when the user asks about top spenders, expensive users, per-user LLM cost, user-level cost drivers, or patterns behind high AI observability spend.\n",{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[888,890,893,896],{"name":889,"slug":31,"type":13},"Analytics",{"name":891,"slug":892,"type":13},"Cost Optimization","cost-optimization",{"name":894,"slug":895,"type":13},"Observability","observability",{"name":9,"slug":8,"type":13},"2026-07-28T05:34:11.117757",{"slug":899,"name":899,"fn":900,"description":901,"org":902,"tags":903,"stars":23,"repoUrl":24,"updatedAt":909},"auditing-endpoints","audit PostHog project endpoints","Audit every endpoint in a PostHog project for staleness, failed materialisations, and unused materialised versions. Use when the user asks \"what endpoints can I clean up?\", \"are any of my endpoints broken?\", \"which materialised versions are still being called?\", or wants a one-shot cleanup pass over the Endpoints product. Produces a prioritised report grouped by issue type, with recommended actions but does not modify anything without explicit confirmation.\n",{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[904,905,908],{"name":889,"slug":31,"type":13},{"name":906,"slug":907,"type":13},"Audit","audit",{"name":9,"slug":8,"type":13},"2026-06-08T08:08:33.693989",{"slug":911,"name":911,"fn":912,"description":913,"org":914,"tags":915,"stars":23,"repoUrl":24,"updatedAt":921},"auditing-warehouse-source-health","audit PostHog data warehouse source health","Audit the health of a PostHog project's data warehouse sources and syncs — find every broken or degraded source connection, sync schema, and webhook channel. Use when the user asks \"why are my imports failing?\", \"what's broken with my sources?\", \"why is my warehouse data stale?\", or wants a one-shot triage of source\u002Fsync health before deciding where to dig in. Produces a prioritized report grouped by severity, with recommended next steps. For materialized-view health use `auditing-warehouse-view-health`; for a single failing sync use `diagnosing-failed-warehouse-syncs`.\n",{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[916,917,919,920],{"name":906,"slug":907,"type":13},{"name":918,"slug":33,"type":13},"Data Warehouse",{"name":894,"slug":895,"type":13},{"name":9,"slug":8,"type":13},"2026-06-18T08:22:57.67984",{"slug":923,"name":923,"fn":924,"description":925,"org":926,"tags":927,"stars":23,"repoUrl":24,"updatedAt":934},"auditing-warehouse-view-health","audit PostHog materialized view health","Audit the health of a PostHog project's materialized views (saved queries) — find every failed materialization and flag unused or stale materialized views that cost storage and compute. Use when the user asks \"which of my views are broken?\", \"why is this materialized view failing?\", \"are any of my views wasting compute?\", or wants a one-shot triage of view health. For source\u002Fsync health use `auditing-warehouse-source-health`.\n",{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[928,929,930,933],{"name":906,"slug":907,"type":13},{"name":918,"slug":33,"type":13},{"name":931,"slug":932,"type":13},"Performance","performance",{"name":9,"slug":8,"type":13},"2026-06-18T08:25:10.936787",{"slug":936,"name":936,"fn":937,"description":938,"org":939,"tags":940,"stars":23,"repoUrl":24,"updatedAt":949},"authoring-error-tracking-alerts","author PostHog error tracking alerts","Author error tracking alerts that fire when an issue is created, reopened, or starts spiking. Use when the user asks to set up error notifications, route exceptions to Slack\u002Fwebhook\u002FLinear, or evaluate which error events are worth alerting on. Covers trigger-event selection, integration choice, dedup against existing alerts, and shipping with the canonical message body shape.\n",{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[941,944,947,948],{"name":942,"slug":943,"type":13},"Alerting","alerting",{"name":945,"slug":946,"type":13},"Debugging","debugging",{"name":894,"slug":895,"type":13},{"name":9,"slug":8,"type":13},"2026-06-18T08:24:40.318583",{"slug":951,"name":951,"fn":952,"description":953,"org":954,"tags":955,"stars":23,"repoUrl":24,"updatedAt":965},"authoring-log-alerts","author log alerts in PostHog","Author useful, low-noise log alerts on services in a PostHog project. Use when the user asks to set up alerts for their logs, suggest alerts they should add, or evaluate whether a service is worth monitoring. Covers service triage, baseline characterisation, threshold drafting, back-testing via simulate, and shipping with a notification destination.\n",{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[956,957,960,961,964],{"name":889,"slug":31,"type":13},{"name":958,"slug":959,"type":13},"Monitoring","monitoring",{"name":894,"slug":895,"type":13},{"name":962,"slug":963,"type":13},"Operations","operations",{"name":9,"slug":8,"type":13},"2026-07-18T05:10:54.430898",{"slug":967,"name":967,"fn":968,"description":969,"org":970,"tags":971,"stars":23,"repoUrl":24,"updatedAt":982},"building-workflows","build and edit PostHog workflows","Build, edit, test, enable, and monitor PostHog workflows over MCP. Author the action\u002Fedge graph so it runs and opens cleanly in the visual editor, then change drafts surgically with patch operations. Use when asked to build, set up, automate, change, fix, or debug a workflow, campaign, broadcast, drip sequence, or event-triggered automation in the workflows product.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[972,975,978,979],{"name":973,"slug":974,"type":13},"Automation","automation",{"name":976,"slug":977,"type":13},"MCP","mcp",{"name":9,"slug":8,"type":13},{"name":980,"slug":981,"type":13},"Workflow Automation","workflow-automation","2026-07-28T05:34:12.167015",61,{"items":985,"total":1102},[986,993,999,1006,1013,1020,1028,1035,1049,1064,1074,1092],{"slug":883,"name":883,"fn":884,"description":885,"org":987,"tags":988,"stars":23,"repoUrl":24,"updatedAt":897},{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[989,990,991,992],{"name":889,"slug":31,"type":13},{"name":891,"slug":892,"type":13},{"name":894,"slug":895,"type":13},{"name":9,"slug":8,"type":13},{"slug":899,"name":899,"fn":900,"description":901,"org":994,"tags":995,"stars":23,"repoUrl":24,"updatedAt":909},{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[996,997,998],{"name":889,"slug":31,"type":13},{"name":906,"slug":907,"type":13},{"name":9,"slug":8,"type":13},{"slug":911,"name":911,"fn":912,"description":913,"org":1000,"tags":1001,"stars":23,"repoUrl":24,"updatedAt":921},{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[1002,1003,1004,1005],{"name":906,"slug":907,"type":13},{"name":918,"slug":33,"type":13},{"name":894,"slug":895,"type":13},{"name":9,"slug":8,"type":13},{"slug":923,"name":923,"fn":924,"description":925,"org":1007,"tags":1008,"stars":23,"repoUrl":24,"updatedAt":934},{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[1009,1010,1011,1012],{"name":906,"slug":907,"type":13},{"name":918,"slug":33,"type":13},{"name":931,"slug":932,"type":13},{"name":9,"slug":8,"type":13},{"slug":936,"name":936,"fn":937,"description":938,"org":1014,"tags":1015,"stars":23,"repoUrl":24,"updatedAt":949},{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[1016,1017,1018,1019],{"name":942,"slug":943,"type":13},{"name":945,"slug":946,"type":13},{"name":894,"slug":895,"type":13},{"name":9,"slug":8,"type":13},{"slug":951,"name":951,"fn":952,"description":953,"org":1021,"tags":1022,"stars":23,"repoUrl":24,"updatedAt":965},{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[1023,1024,1025,1026,1027],{"name":889,"slug":31,"type":13},{"name":958,"slug":959,"type":13},{"name":894,"slug":895,"type":13},{"name":962,"slug":963,"type":13},{"name":9,"slug":8,"type":13},{"slug":967,"name":967,"fn":968,"description":969,"org":1029,"tags":1030,"stars":23,"repoUrl":24,"updatedAt":982},{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[1031,1032,1033,1034],{"name":973,"slug":974,"type":13},{"name":976,"slug":977,"type":13},{"name":9,"slug":8,"type":13},{"name":980,"slug":981,"type":13},{"slug":1036,"name":1036,"fn":1037,"description":1038,"org":1039,"tags":1040,"stars":23,"repoUrl":24,"updatedAt":1048},"check-posthog-loading","inspect PostHog SDK loading across URLs","Inspect how the PostHog JavaScript SDK is loaded across a list of URLs. Use to confirm consistent installation across pages, find pages missing the snippet, detect mismatched API keys or hosts between pages, and verify the load method (head snippet vs deferred vs array.js).\n",{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[1041,1042,1043,1046,1047],{"name":889,"slug":31,"type":13},{"name":945,"slug":946,"type":13},{"name":1044,"slug":1045,"type":13},"Frontend","frontend",{"name":894,"slug":895,"type":13},{"name":9,"slug":8,"type":13},"2026-05-07T05:56:19.828048",{"slug":1050,"name":1050,"fn":1051,"description":1052,"org":1053,"tags":1054,"stars":23,"repoUrl":24,"updatedAt":1063},"consuming-endpoints-from-client-code","integrate PostHog endpoints into client applications","Wire a PostHog endpoint into a client app or SDK. Covers fetching the OpenAPI spec, generating a typed client with openapi-generator or @hey-api\u002Fopenapi-ts, sending the right auth header, shaping the variables payload (HogQL code_name vs insight breakdown property), handling rate-limit and materialised-endpoint error responses. Use when the user says \"how do I call my endpoint\", \"generate a client for this\", or \"what auth header do I use\".\n",{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[1055,1058,1059,1060],{"name":1056,"slug":1057,"type":13},"API Development","api-development",{"name":1044,"slug":1045,"type":13},{"name":9,"slug":8,"type":13},{"name":1061,"slug":1062,"type":13},"SDK","sdk","2026-06-08T08:08:34.929454",{"slug":1065,"name":1065,"fn":1066,"description":1067,"org":1068,"tags":1069,"stars":23,"repoUrl":24,"updatedAt":1073},"copying-endpoints-across-projects","copy PostHog endpoints across projects","Copy a PostHog endpoint (a saved HogQL\u002Finsight query exposed as an API route) to another project in the same organization, or duplicate it under a new name in the same project. Use when the user wants to duplicate an endpoint, promote an endpoint from staging to production, replicate an endpoint's query\u002Fvariables\u002Ffreshness config in another workspace, or clone an endpoint to iterate on it. Unlike feature flags and experiments, endpoints have NO native cross-project copy tool — this skill covers the read-then-recreate flow (endpoint-get then endpoint-create), the active-project switching it requires, name-collision checks, and the safe defaults (land unmaterialised in the target, verify with endpoint-run). Does not cover editing endpoint versions (see managing-endpoint-versions) or authoring a brand-new endpoint from scratch (see creating-an-endpoint).\n",{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[1070,1071,1072],{"name":1056,"slug":1057,"type":13},{"name":962,"slug":963,"type":13},{"name":9,"slug":8,"type":13},"2026-07-15T05:29:58.442727",{"slug":1075,"name":1075,"fn":1076,"description":1077,"org":1078,"tags":1079,"stars":23,"repoUrl":24,"updatedAt":1091},"creating-ai-subscription","schedule recurring AI-generated PostHog reports","Create a recurring AI-generated PostHog report — schedule a free-text prompt to run on a cron, with the LLM-synthesized markdown delivered to email or Slack on each tick. Use when the user wants a recurring AI summary of X on any cadence (daily, weekly, monthly, yearly) rather than a one-off report. (To attach an AI summary to an existing insight\u002Fdashboard subscription instead of a free-text prompt, see `managing-subscriptions` and its `summary_enabled` option.)\n",{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[1080,1081,1084,1085,1088],{"name":973,"slug":974,"type":13},{"name":1082,"slug":1083,"type":13},"Email","email",{"name":9,"slug":8,"type":13},{"name":1086,"slug":1087,"type":13},"Reporting","reporting",{"name":1089,"slug":1090,"type":13},"Slack","slack","2026-06-09T07:32:27.935712",{"slug":1093,"name":1093,"fn":1094,"description":1095,"org":1096,"tags":1097,"stars":23,"repoUrl":24,"updatedAt":1101},"creating-an-endpoint","create PostHog API endpoints","Create a PostHog endpoint with the right shape on the first try — covers query kind choice, name conventions, what to expose as variables (HogQL code_name vs insight breakdown), data_freshness_seconds, and whether to materialise on day one. Use when the user says \"create an endpoint\", \"expose this query as an API\", \"turn this insight into an endpoint\", or asks for help structuring a new endpoint. Steers away from common mistakes: materialising a query with cohort breakdowns or compare mode, inline-only variables on a materialised endpoint, unbounded date ranges, ambiguous names.\n",{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[1098,1099,1100],{"name":889,"slug":31,"type":13},{"name":1056,"slug":1057,"type":13},{"name":9,"slug":8,"type":13},"2026-06-08T08:08:29.624498",231]