{"id":53918,"date":"2025-09-22T14:47:37","date_gmt":"2025-09-22T04:47:37","guid":{"rendered":"https:\/\/www.cloudproinc.com.au\/?p=53918"},"modified":"2025-09-22T14:47:39","modified_gmt":"2025-09-22T04:47:39","slug":"securing-streamlit-environment-vars-with-toml","status":"publish","type":"post","link":"https:\/\/cloudproinc.com.au\/index.php\/2025\/09\/22\/securing-streamlit-environment-vars-with-toml\/","title":{"rendered":"Securing Streamlit Environment Vars with TOML"},"content":{"rendered":"\n<p>In this blog post A Practical Guide to Securing Streamlit Environment Vars with TOML we will show you how to keep API keys, database URLs, and service credentials safe while building fast Streamlit apps.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>Secrets are the backbone of most apps. If you hardcode them, you risk leaks; if you make them too hard to manage, teams slow down. This post explains a clean, practical way to secure environment variables for Streamlit using TOML files. We start with the big picture, then walk through hands-on steps you can apply today.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-why-this-matters\">Why this matters<\/h2>\n\n\n\n<p><a href=\"https:\/\/www.cloudproinc.com.au\/index.php\/category\/streamlit\/\">Streamlit <\/a>makes it simple to build data apps. But simplicity should not mean unsafe. A disciplined secrets approach prevents accidental commits of API keys, reduces blast radius if a key leaks, and keeps dev, test, and prod neatly separated. Using TOML for secrets gives you an easy, typed, and structured configuration that Streamlit understands out of the box.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-the-technology-behind-it\">The technology behind it<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-streamlit-secrets\">Streamlit secrets<\/h3>\n\n\n\n<p>Streamlit provides <code>st.secrets<\/code>, a secure configuration interface that loads from a <code>.streamlit\/secrets.toml<\/code> file during local development. On Streamlit Community Cloud, you store secrets in the app settings UI; those values are injected into <code>st.secrets<\/code> at runtime, never committed to your repo.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-toml-essentials\">TOML essentials<\/h3>\n\n\n\n<p>TOML (Tom\u2019s Obvious, Minimal Language) is a human-friendly configuration format with typed values and nested sections. Think of it like a safer, more structured alternative to <code>.env<\/code> files. It supports strings, integers, booleans, arrays, and tables (sections), which makes it ideal for grouping credentials and environment settings. Streamlit natively reads TOML for secrets, which is why it\u2019s the preferred format here.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-high-level-workflow\">High-level workflow<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Local development: Place secrets in <code>.streamlit\/secrets.toml<\/code>, which you never commit.<\/li>\n\n\n\n<li>Streamlit Community Cloud: Add secrets in the app\u2019s \u201cSecrets\u201d section; <code>st.secrets<\/code> reads them at runtime.<\/li>\n\n\n\n<li>Other hosting (Docker, VM, Kubernetes): Mount or generate a <code>secrets.toml<\/code> at deploy time, or read from environment variables as a fallback.<\/li>\n<\/ul>\n\n\n\n<p>This pattern keeps secrets out of your codebase and makes promotion from dev to prod predictable.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-project-structure\">Project structure<\/h2>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-26ffdf2c596208612e844a0d56acc657\"><code>my-streamlit-app\/\n\u251c\u2500 app.py\n\u251c\u2500 requirements.txt\n\u2514\u2500 .streamlit\/\n   \u2514\u2500 secrets.toml   # local only; DO NOT COMMIT\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-create-your-secrets-toml\">Create your secrets.toml<\/h2>\n\n\n\n<p>Define logical sections so you can rotate secrets independently and limit what each component can access.<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-9936367677f7ab83c1ce9662afdde6f9\"><code># .streamlit\/secrets.toml (local dev only)\n&#91;api]\nopenai_key = \"&lt;your-openai-key&gt;\"\nmaps_key = \"&lt;your-maps-key&gt;\"\n\n&#91;database]\nurl = \"postgresql+psycopg2:\/\/user:pass@host:5432\/dbname\"\n\n&#91;email]\nsmtp_host = \"smtp.example.com\"\nsmtp_user = \"apikey\"\nsmtp_password = \"&lt;your-smtp-password&gt;\"\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-keep-it-out-of-git\">Keep it out of git<\/h3>\n\n\n\n<p>Add this to your <code>.gitignore<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-b17d6698bcd301380570c10b2df40633\"><code>.streamlit\/secrets.toml\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-use-secrets-in-your-streamlit-app\">Use secrets in your Streamlit app<\/h2>\n\n\n\n<p>Access values through <code>st.secrets<\/code>. Optionally fall back to OS environment variables so your app can run even if a TOML file isn\u2019t present in production.<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-d3f7edbf0ca6d7ac9c129fec83493ce0\"><code>import os\nimport streamlit as st\nfrom sqlalchemy import create_engine\n\n# Prefer st.secrets; fall back to environment variables when needed\nOPENAI_KEY = st.secrets.get(\"api\", {}).get(\"openai_key\") or os.getenv(\"OPENAI_API_KEY\")\nDB_URL = st.secrets.get(\"database\", {}).get(\"url\") or os.getenv(\"DATABASE_URL\")\n\n# Example: use a DB engine without logging credentials\nengine = create_engine(DB_URL) if DB_URL else None\n\nst.title(\"Secrets demo\")\nif OPENAI_KEY:\n    st.write(\"OpenAI key configured.\")\nelse:\n    st.warning(\"OpenAI key missing. Set api.openai_key in secrets or OPENAI_API_KEY env var.\")\n\nif engine:\n    st.write(\"Database configured for:\", engine.url.database)  # safe: database name only\nelse:\n    st.warning(\"Database URL missing. Set database.url or DATABASE_URL.\")\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-never-log-secrets\">Never log secrets<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Do not print or write secrets to Streamlit widgets or logs.<\/li>\n\n\n\n<li>When debugging, reveal only non-sensitive portions, e.g., hostnames or database names.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-local-vs-cloud\">Local vs cloud<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-local-development\">Local development<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create <code>.streamlit\/secrets.toml<\/code> as shown above.<\/li>\n\n\n\n<li>Run <code>streamlit run app.py<\/code>. <code>st.secrets<\/code> will load your TOML values.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-streamlit-community-cloud\">Streamlit Community Cloud<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Open the app\u2019s settings and add secrets under \u201cSecrets\u201d.<\/li>\n\n\n\n<li>Those values are encrypted and available via <code>st.secrets<\/code> at runtime.<\/li>\n\n\n\n<li>You don\u2019t need a <code>secrets.toml<\/code> in the repo for cloud usage.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-docker-and-other-hosts\">Docker and other hosts<\/h3>\n\n\n\n<p>Mount the secrets file at runtime so it never bakes into your image layers:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-7ac00b2bfb9b828435008d58b819d874\"><code># Build the image\ndocker build -t my-streamlit-app .\n\n# Run with secrets mounted into the container\ndocker run \\\n  -p 8501:8501 \\\n  -v $PWD\/.streamlit\/secrets.toml:\/app\/.streamlit\/secrets.toml:ro \\\n  my-streamlit-app\n<\/code><\/pre>\n\n\n\n<p>Alternatively, generate the file on the host during deployment and keep it out of your source repository and image.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-ci-cd-patterns\">CI\/CD patterns<\/h2>\n\n\n\n<p>In pipelines (e.g., GitHub Actions, GitLab CI, Azure DevOps), store secrets in the platform\u2019s secure vault. At deploy time, write them into <code>.streamlit\/secrets.toml<\/code> just before starting the app.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-github-actions-example\">GitHub Actions example<\/h3>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-5a4cf01faff67e1c65a8e1468ce41c15\"><code>name: Deploy Streamlit app\non: &#91;push]\n\njobs:\n  deploy:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions\/checkout@v4\n      - uses: actions\/setup-python@v5\n        with:\n          python-version: \"3.11\"\n\n      - name: Write secrets to TOML\n        run: |\n          mkdir -p .streamlit\n          cat &gt; .streamlit\/secrets.toml &lt;&lt; 'EOF'\n          &#91;api]\n          openai_key = \"${{ secrets.OPENAI_API_KEY }}\"\n          &#91;database]\n          url = \"${{ secrets.DATABASE_URL }}\"\n          EOF\n\n      - run: pip install -r requirements.txt\n      - run: streamlit run app.py --server.headless true\n<\/code><\/pre>\n\n\n\n<p>Notes:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Never echo secret values in logs.<\/li>\n\n\n\n<li>Grant the least permissions needed to deploy.<\/li>\n\n\n\n<li>Rotate repository or environment secrets periodically.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-validate-required-secrets\">Validate required secrets<\/h2>\n\n\n\n<p>Fail fast with a small helper so missing secrets don\u2019t become runtime surprises.<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-eff2533975c705d798837a063f87dfdc\"><code>import streamlit as st\n\nREQUIRED = &#91;\n    (\"api\", \"openai_key\"),\n    (\"database\", \"url\"),\n]\n\ndef require(secrets, section, key):\n    if section not in secrets or key not in secrets&#91;section]:\n        raise KeyError(f\"Missing secret: &#91;{section}] {key}\")\n    return secrets&#91;section]&#91;key]\n\ntry:\n    OPENAI_KEY = require(st.secrets, \"api\", \"openai_key\")\n    DB_URL = require(st.secrets, \"database\", \"url\")\nexcept KeyError as e:\n    st.error(str(e))\n    st.stop()\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-environment-variables-as-a-fallback\">Environment variables as a fallback<\/h2>\n\n\n\n<p>Some platforms prefer environment variables only. Keep a thin adapter in your code so you can run in both modes.<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-2dc39f8ad402d917e4c27ab3393d3321\"><code>import os\nimport streamlit as st\n\ndef get_secret(section, key, env_var=None):\n    # Try st.secrets first\n    val = st.secrets.get(section, {}).get(key) if section in st.secrets else None\n    if val:\n        return val\n    # Fallback to environment variable\n    if env_var:\n        return os.getenv(env_var)\n    return None\n\nOPENAI_KEY = get_secret(\"api\", \"openai_key\", env_var=\"OPENAI_API_KEY\")\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-rotation-revocation-and-scope\">Rotation, revocation, and scope<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use separate keys per environment (dev, staging, prod) to limit blast radius.<\/li>\n\n\n\n<li>Rotate keys on a schedule or after personnel changes.<\/li>\n\n\n\n<li>Prefer narrowly scoped credentials (e.g., DB user with read-only access for dashboards).<\/li>\n\n\n\n<li>Revoke on suspicion of leakage and re-deploy immediately with new secrets.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-common-pitfalls-and-fixes\">Common pitfalls and fixes<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Secrets committed to git: Remove the file, rotate keys immediately, and add to <code>.gitignore<\/code>.<\/li>\n\n\n\n<li>KeyError when reading <code>st.secrets<\/code>: Ensure the TOML structure matches your code\u2019s expected sections and keys.<\/li>\n\n\n\n<li>Docker can\u2019t find secrets: Verify the volume mount path matches your container\u2019s working directory and that the file has read permissions.<\/li>\n\n\n\n<li>Mixed environments: Log which environment you are in (dev\/staging\/prod) without revealing secrets.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-security-checklist\">Security checklist<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Never hardcode secrets in code, notebooks, or markdown.<\/li>\n\n\n\n<li>Keep <code>.streamlit\/secrets.toml<\/code> out of version control.<\/li>\n\n\n\n<li>Use <code>st.secrets<\/code> for Streamlit-native loading; use environment variables as a fallback.<\/li>\n\n\n\n<li>Validate required secrets at startup and fail fast.<\/li>\n\n\n\n<li>Rotate, scope, and audit keys regularly.<\/li>\n\n\n\n<li>In CI\/CD, write secrets at runtime; do not bake into images.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-wrapping-up\">Wrapping up<\/h2>\n\n\n\n<p>Securing Streamlit apps doesn\u2019t have to be complicated. By leaning on TOML-based secrets and a few disciplined patterns, you get safer configuration, simpler deployments, and fewer surprises. Whether you deploy on Streamlit Community Cloud or your own infrastructure, the approach above scales cleanly from a single developer to a larger team.<\/p>\n\n\n\n<p>If your team wants a second set of eyes on security, configuration, or CI\/CD for data apps, CloudProinc.com.au can help you blueprint and implement a robust setup tailored to your stack.<\/p>\n\n\n\n<ul class=\"wp-block-yoast-seo-related-links yoast-seo-related-links\">\n<li><a href=\"https:\/\/cloudproinc.com.au\/index.php\/2025\/09\/20\/build-data-driven-apps-with-streamlit\/\">Build Data Driven Apps With Streamlit<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/21\/build-a-chat-bot-with-streamlit\/\">Build a Chat Bot with Streamlit<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/cloudproinc.com.au\/index.php\/2025\/09\/20\/how-to-secure-api-keys-with-python\/\">How to Secure API Keys with Python<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/08\/26\/graphrag-explained\/\">GraphRAG Explained<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/14\/mastering-docker-environment-variables-with-docker\/\">Mastering Docker environment variables with Docker<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Protect API keys and credentials in Streamlit using TOML-based secrets, safe local and cloud workflows, and CI\/CD patterns for repeatable, secure deployments.<\/p>\n","protected":false},"author":1,"featured_media":53919,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_yoast_wpseo_focuskw":"Securing Streamlit Environment Vars with TOML","_yoast_wpseo_title":"","_yoast_wpseo_metadesc":"Learn how to secure your Streamlit environment vars with TOML to protect your API keys and credentials effectively.","_yoast_wpseo_opengraph-title":"","_yoast_wpseo_opengraph-description":"","_yoast_wpseo_twitter-title":"","_yoast_wpseo_twitter-description":"","_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[13,89],"tags":[],"class_list":["post-53918","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","category-streamlit"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Securing Streamlit Environment Vars with TOML - CPI Consulting<\/title>\n<meta name=\"description\" content=\"Learn how to secure your Streamlit environment vars with TOML to protect your API keys and credentials effectively.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cloudproinc.com.au\/index.php\/2025\/09\/22\/securing-streamlit-environment-vars-with-toml\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Securing Streamlit Environment Vars with TOML\" \/>\n<meta property=\"og:description\" content=\"Learn how to secure your Streamlit environment vars with TOML to protect your API keys and credentials effectively.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cloudproinc.com.au\/index.php\/2025\/09\/22\/securing-streamlit-environment-vars-with-toml\/\" \/>\n<meta property=\"og:site_name\" content=\"CPI Consulting\" \/>\n<meta property=\"article:published_time\" content=\"2025-09-22T04:47:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-09-22T04:47:39+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cloudproinc.com.au\/wp-content\/uploads\/2025\/09\/a-practical-guide-to-securing-streamlit-environment-vars-with-toml.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1536\" \/>\n\t<meta property=\"og:image:height\" content=\"1024\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"CPI Staff\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"CPI Staff\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/22\\\/securing-streamlit-environment-vars-with-toml\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/22\\\/securing-streamlit-environment-vars-with-toml\\\/\"},\"author\":{\"name\":\"CPI Staff\",\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/#\\\/schema\\\/person\\\/192eeeb0ce91062126ce3822ae88fe6e\"},\"headline\":\"Securing Streamlit Environment Vars with TOML\",\"datePublished\":\"2025-09-22T04:47:37+00:00\",\"dateModified\":\"2025-09-22T04:47:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/22\\\/securing-streamlit-environment-vars-with-toml\\\/\"},\"wordCount\":881,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/22\\\/securing-streamlit-environment-vars-with-toml\\\/#primaryimage\"},\"thumbnailUrl\":\"\\\/wp-content\\\/uploads\\\/2025\\\/09\\\/a-practical-guide-to-securing-streamlit-environment-vars-with-toml.png\",\"articleSection\":[\"Blog\",\"Streamlit\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/22\\\/securing-streamlit-environment-vars-with-toml\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/22\\\/securing-streamlit-environment-vars-with-toml\\\/\",\"url\":\"https:\\\/\\\/cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/22\\\/securing-streamlit-environment-vars-with-toml\\\/\",\"name\":\"Securing Streamlit Environment Vars with TOML - CPI Consulting\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/22\\\/securing-streamlit-environment-vars-with-toml\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/22\\\/securing-streamlit-environment-vars-with-toml\\\/#primaryimage\"},\"thumbnailUrl\":\"\\\/wp-content\\\/uploads\\\/2025\\\/09\\\/a-practical-guide-to-securing-streamlit-environment-vars-with-toml.png\",\"datePublished\":\"2025-09-22T04:47:37+00:00\",\"dateModified\":\"2025-09-22T04:47:39+00:00\",\"description\":\"Learn how to secure your Streamlit environment vars with TOML to protect your API keys and credentials effectively.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/22\\\/securing-streamlit-environment-vars-with-toml\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/22\\\/securing-streamlit-environment-vars-with-toml\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/22\\\/securing-streamlit-environment-vars-with-toml\\\/#primaryimage\",\"url\":\"\\\/wp-content\\\/uploads\\\/2025\\\/09\\\/a-practical-guide-to-securing-streamlit-environment-vars-with-toml.png\",\"contentUrl\":\"\\\/wp-content\\\/uploads\\\/2025\\\/09\\\/a-practical-guide-to-securing-streamlit-environment-vars-with-toml.png\",\"width\":1536,\"height\":1024},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/22\\\/securing-streamlit-environment-vars-with-toml\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Securing Streamlit Environment Vars with TOML\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/#website\",\"url\":\"https:\\\/\\\/cloudproinc.com.au\\\/\",\"name\":\"Cloud Pro Inc - CPI Consulting Pty Ltd\",\"description\":\"Cloud, AI &amp; Cybersecurity Consulting | Melbourne\",\"publisher\":{\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/cloudproinc.com.au\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/#organization\",\"name\":\"Cloud Pro Inc - Cloud Pro Inc - CPI Consulting Pty Ltd\",\"url\":\"https:\\\/\\\/cloudproinc.com.au\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/favfinalfile.png\",\"contentUrl\":\"\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/favfinalfile.png\",\"width\":500,\"height\":500,\"caption\":\"Cloud Pro Inc - Cloud Pro Inc - CPI Consulting Pty Ltd\"},\"image\":{\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/#\\\/schema\\\/person\\\/192eeeb0ce91062126ce3822ae88fe6e\",\"name\":\"CPI Staff\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2d96eeb53b791d92c8c50dd667e3beec92c93253bb6ff21c02cfa8ca73665c70?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2d96eeb53b791d92c8c50dd667e3beec92c93253bb6ff21c02cfa8ca73665c70?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2d96eeb53b791d92c8c50dd667e3beec92c93253bb6ff21c02cfa8ca73665c70?s=96&d=mm&r=g\",\"caption\":\"CPI Staff\"},\"sameAs\":[\"http:\\\/\\\/www.cloudproinc.com.au\"],\"url\":\"https:\\\/\\\/cloudproinc.com.au\\\/index.php\\\/author\\\/cpiadmin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Securing Streamlit Environment Vars with TOML - CPI Consulting","description":"Learn how to secure your Streamlit environment vars with TOML to protect your API keys and credentials effectively.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/cloudproinc.com.au\/index.php\/2025\/09\/22\/securing-streamlit-environment-vars-with-toml\/","og_locale":"en_US","og_type":"article","og_title":"Securing Streamlit Environment Vars with TOML","og_description":"Learn how to secure your Streamlit environment vars with TOML to protect your API keys and credentials effectively.","og_url":"https:\/\/cloudproinc.com.au\/index.php\/2025\/09\/22\/securing-streamlit-environment-vars-with-toml\/","og_site_name":"CPI Consulting","article_published_time":"2025-09-22T04:47:37+00:00","article_modified_time":"2025-09-22T04:47:39+00:00","og_image":[{"width":1536,"height":1024,"url":"https:\/\/cloudproinc.com.au\/wp-content\/uploads\/2025\/09\/a-practical-guide-to-securing-streamlit-environment-vars-with-toml.png","type":"image\/png"}],"author":"CPI Staff","twitter_card":"summary_large_image","twitter_misc":{"Written by":"CPI Staff","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/cloudproinc.com.au\/index.php\/2025\/09\/22\/securing-streamlit-environment-vars-with-toml\/#article","isPartOf":{"@id":"https:\/\/cloudproinc.com.au\/index.php\/2025\/09\/22\/securing-streamlit-environment-vars-with-toml\/"},"author":{"name":"CPI Staff","@id":"https:\/\/cloudproinc.com.au\/#\/schema\/person\/192eeeb0ce91062126ce3822ae88fe6e"},"headline":"Securing Streamlit Environment Vars with TOML","datePublished":"2025-09-22T04:47:37+00:00","dateModified":"2025-09-22T04:47:39+00:00","mainEntityOfPage":{"@id":"https:\/\/cloudproinc.com.au\/index.php\/2025\/09\/22\/securing-streamlit-environment-vars-with-toml\/"},"wordCount":881,"commentCount":0,"publisher":{"@id":"https:\/\/cloudproinc.com.au\/#organization"},"image":{"@id":"https:\/\/cloudproinc.com.au\/index.php\/2025\/09\/22\/securing-streamlit-environment-vars-with-toml\/#primaryimage"},"thumbnailUrl":"\/wp-content\/uploads\/2025\/09\/a-practical-guide-to-securing-streamlit-environment-vars-with-toml.png","articleSection":["Blog","Streamlit"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/cloudproinc.com.au\/index.php\/2025\/09\/22\/securing-streamlit-environment-vars-with-toml\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/cloudproinc.com.au\/index.php\/2025\/09\/22\/securing-streamlit-environment-vars-with-toml\/","url":"https:\/\/cloudproinc.com.au\/index.php\/2025\/09\/22\/securing-streamlit-environment-vars-with-toml\/","name":"Securing Streamlit Environment Vars with TOML - CPI Consulting","isPartOf":{"@id":"https:\/\/cloudproinc.com.au\/#website"},"primaryImageOfPage":{"@id":"https:\/\/cloudproinc.com.au\/index.php\/2025\/09\/22\/securing-streamlit-environment-vars-with-toml\/#primaryimage"},"image":{"@id":"https:\/\/cloudproinc.com.au\/index.php\/2025\/09\/22\/securing-streamlit-environment-vars-with-toml\/#primaryimage"},"thumbnailUrl":"\/wp-content\/uploads\/2025\/09\/a-practical-guide-to-securing-streamlit-environment-vars-with-toml.png","datePublished":"2025-09-22T04:47:37+00:00","dateModified":"2025-09-22T04:47:39+00:00","description":"Learn how to secure your Streamlit environment vars with TOML to protect your API keys and credentials effectively.","breadcrumb":{"@id":"https:\/\/cloudproinc.com.au\/index.php\/2025\/09\/22\/securing-streamlit-environment-vars-with-toml\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cloudproinc.com.au\/index.php\/2025\/09\/22\/securing-streamlit-environment-vars-with-toml\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudproinc.com.au\/index.php\/2025\/09\/22\/securing-streamlit-environment-vars-with-toml\/#primaryimage","url":"\/wp-content\/uploads\/2025\/09\/a-practical-guide-to-securing-streamlit-environment-vars-with-toml.png","contentUrl":"\/wp-content\/uploads\/2025\/09\/a-practical-guide-to-securing-streamlit-environment-vars-with-toml.png","width":1536,"height":1024},{"@type":"BreadcrumbList","@id":"https:\/\/cloudproinc.com.au\/index.php\/2025\/09\/22\/securing-streamlit-environment-vars-with-toml\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.cloudproinc.com.au\/"},{"@type":"ListItem","position":2,"name":"Securing Streamlit Environment Vars with TOML"}]},{"@type":"WebSite","@id":"https:\/\/cloudproinc.com.au\/#website","url":"https:\/\/cloudproinc.com.au\/","name":"Cloud Pro Inc - CPI Consulting Pty Ltd","description":"Cloud, AI &amp; Cybersecurity Consulting | Melbourne","publisher":{"@id":"https:\/\/cloudproinc.com.au\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cloudproinc.com.au\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/cloudproinc.com.au\/#organization","name":"Cloud Pro Inc - Cloud Pro Inc - CPI Consulting Pty Ltd","url":"https:\/\/cloudproinc.com.au\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudproinc.com.au\/#\/schema\/logo\/image\/","url":"\/wp-content\/uploads\/2022\/01\/favfinalfile.png","contentUrl":"\/wp-content\/uploads\/2022\/01\/favfinalfile.png","width":500,"height":500,"caption":"Cloud Pro Inc - Cloud Pro Inc - CPI Consulting Pty Ltd"},"image":{"@id":"https:\/\/cloudproinc.com.au\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/cloudproinc.com.au\/#\/schema\/person\/192eeeb0ce91062126ce3822ae88fe6e","name":"CPI Staff","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/2d96eeb53b791d92c8c50dd667e3beec92c93253bb6ff21c02cfa8ca73665c70?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/2d96eeb53b791d92c8c50dd667e3beec92c93253bb6ff21c02cfa8ca73665c70?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2d96eeb53b791d92c8c50dd667e3beec92c93253bb6ff21c02cfa8ca73665c70?s=96&d=mm&r=g","caption":"CPI Staff"},"sameAs":["http:\/\/www.cloudproinc.com.au"],"url":"https:\/\/cloudproinc.com.au\/index.php\/author\/cpiadmin\/"}]}},"jetpack_featured_media_url":"\/wp-content\/uploads\/2025\/09\/a-practical-guide-to-securing-streamlit-environment-vars-with-toml.png","jetpack-related-posts":[{"id":53910,"url":"https:\/\/cloudproinc.com.au\/index.php\/2025\/09\/21\/build-a-chat-bot-with-streamlit\/","url_meta":{"origin":53918,"position":0},"title":"Build a Chat Bot with Streamlit","author":"CPI Staff","date":"September 21, 2025","format":false,"excerpt":"A practical, friendly guide to designing, building, and shipping a Streamlit chat bot with modern LLMs, retrieval, and secure deployment for teams.","rel":"","context":"In &quot;AI&quot;","block_context":{"text":"AI","link":"https:\/\/cloudproinc.com.au\/index.php\/category\/ai\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2025\/09\/build-a-chat-bot-with-streamlit-an-end-to-end-guide-for-teams.png","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2025\/09\/build-a-chat-bot-with-streamlit-an-end-to-end-guide-for-teams.png 1x, \/wp-content\/uploads\/2025\/09\/build-a-chat-bot-with-streamlit-an-end-to-end-guide-for-teams.png 1.5x, \/wp-content\/uploads\/2025\/09\/build-a-chat-bot-with-streamlit-an-end-to-end-guide-for-teams.png 2x, \/wp-content\/uploads\/2025\/09\/build-a-chat-bot-with-streamlit-an-end-to-end-guide-for-teams.png 3x, \/wp-content\/uploads\/2025\/09\/build-a-chat-bot-with-streamlit-an-end-to-end-guide-for-teams.png 4x"},"classes":[]},{"id":53902,"url":"https:\/\/cloudproinc.com.au\/index.php\/2025\/09\/20\/build-data-driven-apps-with-streamlit\/","url_meta":{"origin":53918,"position":1},"title":"Build Data Driven Apps With Streamlit","author":"CPI Staff","date":"September 20, 2025","format":false,"excerpt":"Learn how to build production-ready data apps with Streamlit. From architecture to deployment, practical steps and code to move from notebook to interactive app fast.","rel":"","context":"In &quot;Blog&quot;","block_context":{"text":"Blog","link":"https:\/\/cloudproinc.com.au\/index.php\/category\/blog\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2025\/09\/build-data-driven-apps-with-streamlit-that-users-love-to-use.png","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2025\/09\/build-data-driven-apps-with-streamlit-that-users-love-to-use.png 1x, \/wp-content\/uploads\/2025\/09\/build-data-driven-apps-with-streamlit-that-users-love-to-use.png 1.5x, \/wp-content\/uploads\/2025\/09\/build-data-driven-apps-with-streamlit-that-users-love-to-use.png 2x, \/wp-content\/uploads\/2025\/09\/build-data-driven-apps-with-streamlit-that-users-love-to-use.png 3x, \/wp-content\/uploads\/2025\/09\/build-data-driven-apps-with-streamlit-that-users-love-to-use.png 4x"},"classes":[]},{"id":56853,"url":"https:\/\/cloudproinc.com.au\/index.php\/2025\/12\/22\/how-to-use-net-appsettings-json\/","url_meta":{"origin":53918,"position":2},"title":"How to Use .NET appsettings.json","author":"CPI Staff","date":"December 22, 2025","format":false,"excerpt":"Learn how .NET appsettings.json works, how to structure it well, and how to load environment-specific settings safely. Includes practical code examples and common pitfalls to avoid.","rel":"","context":"In &quot;.NET&quot;","block_context":{"text":".NET","link":"https:\/\/cloudproinc.com.au\/index.php\/category\/net\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2025\/12\/post-2.png","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2025\/12\/post-2.png 1x, \/wp-content\/uploads\/2025\/12\/post-2.png 1.5x, \/wp-content\/uploads\/2025\/12\/post-2.png 2x, \/wp-content\/uploads\/2025\/12\/post-2.png 3x, \/wp-content\/uploads\/2025\/12\/post-2.png 4x"},"classes":[]},{"id":53906,"url":"https:\/\/cloudproinc.com.au\/index.php\/2025\/09\/20\/how-to-secure-api-keys-with-python\/","url_meta":{"origin":53918,"position":3},"title":"How to Secure API Keys with Python","author":"CPI Staff","date":"September 20, 2025","format":false,"excerpt":"Practical patterns to protect API keys in Python. Learn safe storage, retrieval, rotation, and CI\/CD hygiene with code examples and cloud options.","rel":"","context":"In &quot;Blog&quot;","block_context":{"text":"Blog","link":"https:\/\/cloudproinc.com.au\/index.php\/category\/blog\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2025\/09\/how-to-secure-api-keys-with-python-for-apps-and-infrastructure.png","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2025\/09\/how-to-secure-api-keys-with-python-for-apps-and-infrastructure.png 1x, \/wp-content\/uploads\/2025\/09\/how-to-secure-api-keys-with-python-for-apps-and-infrastructure.png 1.5x, \/wp-content\/uploads\/2025\/09\/how-to-secure-api-keys-with-python-for-apps-and-infrastructure.png 2x, \/wp-content\/uploads\/2025\/09\/how-to-secure-api-keys-with-python-for-apps-and-infrastructure.png 3x, \/wp-content\/uploads\/2025\/09\/how-to-secure-api-keys-with-python-for-apps-and-infrastructure.png 4x"},"classes":[]},{"id":53959,"url":"https:\/\/cloudproinc.com.au\/index.php\/2025\/09\/25\/supercharge-langchain-apps-with-an-llm-cache\/","url_meta":{"origin":53918,"position":4},"title":"Supercharge LangChain apps with an LLM Cache","author":"CPI Staff","date":"September 25, 2025","format":false,"excerpt":"Cut latency and costs by caching LLM outputs in LangChain. Learn what to cache, when not to, and how to ship in-memory, SQLite, and Redis caches.","rel":"","context":"In &quot;Blog&quot;","block_context":{"text":"Blog","link":"https:\/\/cloudproinc.com.au\/index.php\/category\/blog\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2025\/09\/supercharge-langchain-apps-with-an-llm-cache-for-speed-and-cost.png","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2025\/09\/supercharge-langchain-apps-with-an-llm-cache-for-speed-and-cost.png 1x, \/wp-content\/uploads\/2025\/09\/supercharge-langchain-apps-with-an-llm-cache-for-speed-and-cost.png 1.5x, \/wp-content\/uploads\/2025\/09\/supercharge-langchain-apps-with-an-llm-cache-for-speed-and-cost.png 2x, \/wp-content\/uploads\/2025\/09\/supercharge-langchain-apps-with-an-llm-cache-for-speed-and-cost.png 3x, \/wp-content\/uploads\/2025\/09\/supercharge-langchain-apps-with-an-llm-cache-for-speed-and-cost.png 4x"},"classes":[]},{"id":53573,"url":"https:\/\/cloudproinc.com.au\/index.php\/2025\/08\/06\/how-to-code-and-build-a-gpt-large-language-model\/","url_meta":{"origin":53918,"position":5},"title":"How to Code and Build a GPT Large Language Model","author":"CPI Staff","date":"August 6, 2025","format":false,"excerpt":"In this blog post, you\u2019ll learn how to code and build a GPT LLM from scratch or fine-tune an existing one. We\u2019ll cover the architecture, key tools, libraries, frameworks, and essential resources to get you started fast. Table of contentsUnderstanding GPT LLM ArchitectureModel Architecture DiagramTools and Libraries to Build a\u2026","rel":"","context":"In &quot;AI&quot;","block_context":{"text":"AI","link":"https:\/\/cloudproinc.com.au\/index.php\/category\/ai\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2025\/08\/CreateLLM.png","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2025\/08\/CreateLLM.png 1x, \/wp-content\/uploads\/2025\/08\/CreateLLM.png 1.5x, \/wp-content\/uploads\/2025\/08\/CreateLLM.png 2x, \/wp-content\/uploads\/2025\/08\/CreateLLM.png 3x, \/wp-content\/uploads\/2025\/08\/CreateLLM.png 4x"},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/posts\/53918","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/comments?post=53918"}],"version-history":[{"count":2,"href":"https:\/\/cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/posts\/53918\/revisions"}],"predecessor-version":[{"id":53925,"href":"https:\/\/cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/posts\/53918\/revisions\/53925"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/media\/53919"}],"wp:attachment":[{"href":"https:\/\/cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/media?parent=53918"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/categories?post=53918"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/tags?post=53918"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}