{"id":210,"date":"2025-07-14T18:10:16","date_gmt":"2025-07-15T02:10:16","guid":{"rendered":"https:\/\/www.tonybhimani.com\/programming-blog\/?p=210"},"modified":"2025-07-14T18:25:05","modified_gmt":"2025-07-15T02:25:05","slug":"environment-variables-secure-your-python-secrets","status":"publish","type":"post","link":"https:\/\/www.tonybhimani.com\/programming-blog\/environment-variables-secure-your-python-secrets\/","title":{"rendered":"Environment Variables: Secure Your Python Secrets"},"content":{"rendered":"<p>You&#8217;ve heard it a thousand times: &#8220;Never store secure credentials directly in your code!&#8221; Whether it&#8217;s an API key, a database password, or sensitive configuration, the advice is always the same: use environment variables.<\/p>\n<p>But for many, this often leaves a crucial question unanswered: <em>How exactly do you do that in practice, especially with Python?<\/em> And what&#8217;s to stop a bad actor from just seeing the environment variable name and grabbing the key anyway?<\/p>\n<p>Today, we&#8217;re going to demystify environment variables. We&#8217;ll cover what they are, why they&#8217;re essential for security, how to set them up on different operating systems, and most importantly, how to access them securely in your Python applications. We&#8217;ll also address the &#8220;what if&#8221; scenarios, giving you a comprehensive understanding of this critical security practice.<\/p>\n<h2>Why Environment Variables are Your Best Friend for Secrets<\/h2>\n<p>Imagine your API key is like the key to your digital vault. Would you engrave it on the outside of the vault for anyone to see, or would you keep it separate and only bring it out when needed? Hardcoding secrets in your script is like engraving that key on your vault.<\/p>\n<p>Environment variables offer several compelling advantages:<\/p>\n<ol>\n<li><strong>Security (Primary Benefit):<\/strong> This is the big one. Your secrets are decoupled from your codebase. If your code repository accidentally becomes public (a surprisingly common occurrence!), or if an attacker gains access to your source code, your API key isn&#8217;t sitting there in plain text. This also prevents &#8220;history leakage&#8221; in version control systems like Git.<\/li>\n<li><strong>Flexibility:<\/strong> You can easily change credentials (e.g., rotating an API key) without touching a single line of your Python code. Just update the environment variable, and your application will pick up the new value on its next run.<\/li>\n<li><strong>Portability:<\/strong> Your application can run in different environments (development, testing, staging, production) using the exact same code, but configured with different credentials simply by setting different environment variables for each environment.<\/li>\n<\/ol>\n<h2>Setting Up Your Environment Variables<\/h2>\n<p>The way you set an environment variable depends on your operating system.<\/p>\n<h3>For Linux\/macOS (Bash\/Zsh Terminal)<\/h3>\n<p>You can set a variable for the current terminal session using export. This is great for quick tests:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nexport MY_API_KEY=&quot;your_super_secret_api_key_for_testing&quot;\r\n<\/pre>\n<p>To make it persistent across terminal sessions, you&#8217;ll need to add it to your shell&#8217;s configuration file. Common files include ~\/.bashrc, ~\/.zshrc, or ~\/.profile.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# Add this line to ~\/.bashrc, ~\/.zshrc, or ~\/.profile\r\nexport MY_API_KEY=&quot;your_production_api_key_here&quot;\r\n\r\n# After saving the file, apply the changes (or open a new terminal):\r\nsource ~\/.bashrc  # or ~\/.zshrc or ~\/.profile\r\n<\/pre>\n<h3>For Windows (Command Prompt\/PowerShell)<\/h3>\n<p><strong>Command Prompt (temporary for current session):<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nset MY_API_KEY=&quot;your_super_secret_api_key_for_testing&quot;\r\n<\/pre>\n<p><strong>To make it persistent (requires opening a new Command Prompt window to take effect):<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsetx MY_API_KEY &quot;your_production_api_key_here&quot;\r\n<\/pre>\n<p><strong>PowerShell (temporary for current session):<\/strong><\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n$env:MY_API_KEY=&quot;your_super_secret_api_key_for_testing&quot;\r\n<\/pre>\n<p><strong>To make it persistent on Windows:<\/strong><\/p>\n<p>The most common way is through the System Properties GUI:<\/p>\n<ol>\n<li>Search for &#8220;Environment Variables&#8221; in the Windows search bar and select &#8220;Edit the system environment variables.&#8221;<\/li>\n<li>In the &#8220;System Properties&#8221; window, click &#8220;Environment Variables&#8230;&#8221;<\/li>\n<li>You can then add a new &#8220;User variable&#8221; (for your user account) or &#8220;System variable&#8221; (for all users).<\/li>\n<\/ol>\n<p>Alternatively, you can add it to your PowerShell profile script (usually located at $PROFILE).<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n# Add this line to your PowerShell profile script\r\n$env:MY_API_KEY=&quot;your_production_api_key_here&quot;\r\n<\/pre>\n<h2>Accessing Environment Variables in Python<\/h2>\n<p>Python&#8217;s built-in os module makes accessing environment variables incredibly straightforward using os.environ. This object behaves much like a dictionary.<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport os\r\n\r\n# --- Getting an environment variable securely ---\r\n\r\n# Method 1: Direct access (raises KeyError if not found)\r\ntry:\r\n    api_key = os.environ&#x5B;&#039;MY_API_KEY&#039;]\r\n    print(f&quot;API Key (direct access): {api_key&#x5B;:5]}...&quot;) # Displaying partial for security\r\nexcept KeyError:\r\n    print(&quot;Error: MY_API_KEY environment variable not set. Please set it before running.&quot;)\r\n    # In a real application, you&#039;d likely exit or raise a custom error here.\r\n\r\n# Method 2: Using .get() (Recommended for safety, returns None if not found)\r\n# This prevents your script from crashing if the variable isn&#039;t set.\r\napi_key_safe = os.environ.get(&#039;MY_API_KEY&#039;)\r\n\r\nif api_key_safe:\r\n    print(f&quot;API Key (using .get()): {api_key_safe&#x5B;:5]}...&quot;)\r\n    # Now you can use api_key_safe in your API calls, etc.\r\nelse:\r\n    print(&quot;MY_API_KEY environment variable not found or is empty. Cannot proceed without it.&quot;)\r\n\r\n# --- Example of using the key ---\r\ndef call_external_api(key):\r\n    if key:\r\n        print(f&quot;\\nSuccessfully making an API call with a securely loaded key.&quot;)\r\n        # In a real app: response = requests.post(url, headers={&#039;Authorization&#039;: f&#039;Bearer {key}&#039;})\r\n    else:\r\n        print(&quot;\\nAPI call aborted: No API key available.&quot;)\r\n\r\ncall_external_api(api_key_safe)\r\n<\/pre>\n<p><strong>Crucial Note:<\/strong> In production code, <strong>never<\/strong> print your full API key or sensitive information to the console or logs. The print statements above are purely for demonstration.<\/p>\n<h2>What About Local Development? Enter python-dotenv<\/h2>\n<p>Manually setting environment variables for every local development session can be cumbersome. This is where the python-dotenv library shines. It allows you to create a .env file in your project root, which git then ignores, keeping your local secrets out of version control.<\/p>\n<ol>\n<li>Install python-dotenv:\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\npip install python-dotenv\r\n<\/pre>\n<\/li>\n<li>Create a .env file in your project&#8217;s root directory:\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# .env (add this file to your .gitignore!)\r\nMY_API_KEY=&quot;your_local_dev_api_key&quot;\r\nDATABASE_URL=&quot;postgresql:\/\/user:password@localhost:5432\/mydb&quot;\r\n<\/pre>\n<\/li>\n<li>Add .env to your .gitignore file:\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# .gitignore\r\n.env\r\n<\/pre>\n<\/li>\n<li>Load the variables in your Python script:\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport os\r\nfrom dotenv import load_dotenv\r\n\r\nload_dotenv() # This line loads the variables from .env into os.environ\r\n\r\napi_key = os.environ.get(&#039;MY_API_KEY&#039;)\r\n\r\nif api_key:\r\n    print(f&quot;API Key loaded from .env: {api_key&#x5B;:5]}...&quot;)\r\nelse:\r\n    print(&quot;API Key not found in .env or system environment.&quot;)\r\n<\/pre>\n<\/li>\n<\/ol>\n<p>This setup is ideal for local development, providing convenience without compromising security when it comes to version control.<\/p>\n<h2>The &#8220;What If&#8221;: When Environment Variables Aren&#8217;t Enough<\/h2>\n<p>This brings us to the question: &#8220;If the script is using the environment variable, they will see the variable name. What&#8217;s to keep them from pulling the key from the environment?&#8221;<\/p>\n<p>This hits on a critical point. Environment variables are an excellent first line of defense, primarily protecting against:<\/p>\n<ul>\n<li><strong>Accidental exposure in source code repositories.<\/strong><\/li>\n<li><strong>Secrets being baked into deployment artifacts (like Docker images).<\/strong><\/li>\n<li><strong>Simple code scanning tools finding hardcoded secrets.<\/strong><\/li>\n<\/ul>\n<p>However, if an attacker has already gained <strong>remote code execution (RCE)<\/strong> on your server, container, or local machine, or has achieved root\/administrator access, then they can likely:<\/p>\n<ol>\n<li><strong>Read Environment Variables:<\/strong> Yes, they can simply run a command (printenv on Linux, for example) or a small script to dump all environment variables, including your API key.<\/li>\n<li><strong>Read Files:<\/strong> At this point, they can read any file on your system, including where you might have placed secrets, or logs that might have accidentally captured them.<\/li>\n<li><strong>Inspect Memory\/Processes:<\/strong> More advanced attackers could even inspect the running application&#8217;s memory to extract secrets.<\/li>\n<\/ol>\n<h2>Beyond Environment Variables: Layers of Defense<\/h2>\n<p>So, while environment variables are indispensable, they are not a silver bullet against a deeply compromised system. For robust security, you need a multi-layered approach:<\/p>\n<ol>\n<li><strong>Principle of Least Privilege (PoLP):<\/strong> Your application should only have the minimum permissions it needs. For cloud services (AWS, GCP, Azure), use <strong>IAM Roles or Service Accounts<\/strong> instead of API keys whenever possible. This allows your application to access other cloud services directly, with credentials managed by the cloud provider and often short-lived.<\/li>\n<li><strong>Dedicated Secret Management Systems:<\/strong> For external API keys or secrets not covered by IAM roles, use a dedicated secret manager. These systems securely store, manage, and often rotate secrets.\n<ul>\n<li><strong>Examples:<\/strong> HashiCorp Vault, AWS Secrets Manager, Azure Key Vault, Google Cloud Secret Manager.<\/li>\n<li><strong>How they work:<\/strong> Your application authenticates with the secret manager (often using an IAM role for the authentication step itself) and then <em>requests<\/em> the specific secret it needs at runtime. The secret is never stored persistently on the application server.<\/li>\n<\/ul>\n<\/li>\n<li><strong>Runtime Security &amp; System Hardening:<\/strong>\n<ul>\n<li><strong>Firewalls:<\/strong> Restrict network access.<\/li>\n<li><strong>Regular Patching:<\/strong> Keep your OS and all software up-to-date.<\/li>\n<li><strong>Container Security:<\/strong> If using Docker\/Kubernetes, ensure your containers are hardened.<\/li>\n<li><strong>Intrusion Detection\/Prevention Systems (IDS\/IPS):<\/strong> Monitor for and block malicious activity.<\/li>\n<\/ul>\n<\/li>\n<li><strong>Comprehensive Monitoring and Logging:<\/strong> Quickly detect a breach.<\/li>\n<\/ol>\n<h2>Conclusion<\/h2>\n<p>Environment variables are a foundational security practice that every developer should master. They are your first line of defense against common vulnerabilities like accidentally exposing secrets in your codebase. While they aren&#8217;t a panacea against all forms of attack, they are a critical component of a secure application architecture. By combining them with responsible secret management systems and robust operational security, you can significantly enhance the protection of your sensitive data.<\/p>\n<p>Start implementing this practice today, and sleep a little easier knowing your secrets are better protected.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You&#8217;ve heard it a thousand times: &#8220;Never store secure credentials directly in your code!&#8221; Whether it&#8217;s an API key, a database password, or sensitive configuration, the advice is always the same: use environment variables. But for many, this often leaves a crucial question unanswered: How exactly do you do that in practice, especially with Python? [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[56,57],"tags":[61,66,65,67,64,59,63,58,62,60],"class_list":["post-210","post","type-post","status-publish","format-standard","hentry","category-python-security","category-secret-management","tag-api-keys","tag-configuration-management","tag-data-protection","tag-developer-best-practices","tag-dot-env","tag-environment-variables","tag-python-secrets","tag-python-security","tag-secret-management","tag-secure-coding"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Environment Variables: Secure Your Python Secrets - Tony&#039;s Programming Blog and Development Journal<\/title>\n<meta name=\"description\" content=\"Protect your Python applications from data exposure. Master environment variables, from setup on any OS to secure access &amp; secret management.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.tonybhimani.com\/programming-blog\/environment-variables-secure-your-python-secrets\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Environment Variables: Secure Your Python Secrets - Tony&#039;s Programming Blog and Development Journal\" \/>\n<meta property=\"og:description\" content=\"Protect your Python applications from data exposure. Master environment variables, from setup on any OS to secure access &amp; secret management.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.tonybhimani.com\/programming-blog\/environment-variables-secure-your-python-secrets\/\" \/>\n<meta property=\"og:site_name\" content=\"Tony&#039;s Programming Blog and Development Journal\" \/>\n<meta property=\"article:published_time\" content=\"2025-07-15T02:10:16+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-07-15T02:25:05+00:00\" \/>\n<meta name=\"author\" content=\"Tony\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@TonyBhimani\" \/>\n<meta name=\"twitter:site\" content=\"@TonyBhimani\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Tony\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.tonybhimani.com\/programming-blog\/environment-variables-secure-your-python-secrets\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.tonybhimani.com\/programming-blog\/environment-variables-secure-your-python-secrets\/\"},\"author\":{\"name\":\"Tony\",\"@id\":\"https:\/\/www.tonybhimani.com\/programming-blog\/#\/schema\/person\/036db10e4bc2069453a60f580f91ab88\"},\"headline\":\"Environment Variables: Secure Your Python Secrets\",\"datePublished\":\"2025-07-15T02:10:16+00:00\",\"dateModified\":\"2025-07-15T02:25:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.tonybhimani.com\/programming-blog\/environment-variables-secure-your-python-secrets\/\"},\"wordCount\":1577,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.tonybhimani.com\/programming-blog\/#\/schema\/person\/036db10e4bc2069453a60f580f91ab88\"},\"keywords\":[\"api keys\",\"configuration management\",\"data protection\",\"developer best practices\",\"dot env\",\"environment variables\",\"python secrets\",\"python security\",\"secret management\",\"secure coding\"],\"articleSection\":[\"Python Security\",\"Secret Management\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.tonybhimani.com\/programming-blog\/environment-variables-secure-your-python-secrets\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.tonybhimani.com\/programming-blog\/environment-variables-secure-your-python-secrets\/\",\"url\":\"https:\/\/www.tonybhimani.com\/programming-blog\/environment-variables-secure-your-python-secrets\/\",\"name\":\"Environment Variables: Secure Your Python Secrets - Tony&#039;s Programming Blog and Development Journal\",\"isPartOf\":{\"@id\":\"https:\/\/www.tonybhimani.com\/programming-blog\/#website\"},\"datePublished\":\"2025-07-15T02:10:16+00:00\",\"dateModified\":\"2025-07-15T02:25:05+00:00\",\"description\":\"Protect your Python applications from data exposure. Master environment variables, from setup on any OS to secure access & secret management.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.tonybhimani.com\/programming-blog\/environment-variables-secure-your-python-secrets\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.tonybhimani.com\/programming-blog\/environment-variables-secure-your-python-secrets\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.tonybhimani.com\/programming-blog\/environment-variables-secure-your-python-secrets\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.tonybhimani.com\/programming-blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Environment Variables: Secure Your Python Secrets\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.tonybhimani.com\/programming-blog\/#website\",\"url\":\"https:\/\/www.tonybhimani.com\/programming-blog\/\",\"name\":\"Tony's Programming Blog and Development Journal\",\"description\":\"Sharing is caring... Especially with code\",\"publisher\":{\"@id\":\"https:\/\/www.tonybhimani.com\/programming-blog\/#\/schema\/person\/036db10e4bc2069453a60f580f91ab88\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.tonybhimani.com\/programming-blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.tonybhimani.com\/programming-blog\/#\/schema\/person\/036db10e4bc2069453a60f580f91ab88\",\"name\":\"Tony\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/ed5a2a00dc5d9679e1fd2f29f60ca885a8e0f9d2c1aa2b5dabf05af02663b46c?s=96&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/ed5a2a00dc5d9679e1fd2f29f60ca885a8e0f9d2c1aa2b5dabf05af02663b46c?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/ed5a2a00dc5d9679e1fd2f29f60ca885a8e0f9d2c1aa2b5dabf05af02663b46c?s=96&r=g\",\"caption\":\"Tony\"},\"logo\":{\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/ed5a2a00dc5d9679e1fd2f29f60ca885a8e0f9d2c1aa2b5dabf05af02663b46c?s=96&r=g\"},\"sameAs\":[\"https:\/\/tonybhimani.com\/programming-blog\",\"https:\/\/x.com\/TonyBhimani\",\"https:\/\/www.youtube.com\/tonybhimani\"],\"url\":\"https:\/\/www.tonybhimani.com\/programming-blog\/author\/coding_magik\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Environment Variables: Secure Your Python Secrets - Tony&#039;s Programming Blog and Development Journal","description":"Protect your Python applications from data exposure. Master environment variables, from setup on any OS to secure access & secret management.","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:\/\/www.tonybhimani.com\/programming-blog\/environment-variables-secure-your-python-secrets\/","og_locale":"en_US","og_type":"article","og_title":"Environment Variables: Secure Your Python Secrets - Tony&#039;s Programming Blog and Development Journal","og_description":"Protect your Python applications from data exposure. Master environment variables, from setup on any OS to secure access & secret management.","og_url":"https:\/\/www.tonybhimani.com\/programming-blog\/environment-variables-secure-your-python-secrets\/","og_site_name":"Tony&#039;s Programming Blog and Development Journal","article_published_time":"2025-07-15T02:10:16+00:00","article_modified_time":"2025-07-15T02:25:05+00:00","author":"Tony","twitter_card":"summary_large_image","twitter_creator":"@TonyBhimani","twitter_site":"@TonyBhimani","twitter_misc":{"Written by":"Tony","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.tonybhimani.com\/programming-blog\/environment-variables-secure-your-python-secrets\/#article","isPartOf":{"@id":"https:\/\/www.tonybhimani.com\/programming-blog\/environment-variables-secure-your-python-secrets\/"},"author":{"name":"Tony","@id":"https:\/\/www.tonybhimani.com\/programming-blog\/#\/schema\/person\/036db10e4bc2069453a60f580f91ab88"},"headline":"Environment Variables: Secure Your Python Secrets","datePublished":"2025-07-15T02:10:16+00:00","dateModified":"2025-07-15T02:25:05+00:00","mainEntityOfPage":{"@id":"https:\/\/www.tonybhimani.com\/programming-blog\/environment-variables-secure-your-python-secrets\/"},"wordCount":1577,"commentCount":0,"publisher":{"@id":"https:\/\/www.tonybhimani.com\/programming-blog\/#\/schema\/person\/036db10e4bc2069453a60f580f91ab88"},"keywords":["api keys","configuration management","data protection","developer best practices","dot env","environment variables","python secrets","python security","secret management","secure coding"],"articleSection":["Python Security","Secret Management"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.tonybhimani.com\/programming-blog\/environment-variables-secure-your-python-secrets\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.tonybhimani.com\/programming-blog\/environment-variables-secure-your-python-secrets\/","url":"https:\/\/www.tonybhimani.com\/programming-blog\/environment-variables-secure-your-python-secrets\/","name":"Environment Variables: Secure Your Python Secrets - Tony&#039;s Programming Blog and Development Journal","isPartOf":{"@id":"https:\/\/www.tonybhimani.com\/programming-blog\/#website"},"datePublished":"2025-07-15T02:10:16+00:00","dateModified":"2025-07-15T02:25:05+00:00","description":"Protect your Python applications from data exposure. Master environment variables, from setup on any OS to secure access & secret management.","breadcrumb":{"@id":"https:\/\/www.tonybhimani.com\/programming-blog\/environment-variables-secure-your-python-secrets\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.tonybhimani.com\/programming-blog\/environment-variables-secure-your-python-secrets\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.tonybhimani.com\/programming-blog\/environment-variables-secure-your-python-secrets\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.tonybhimani.com\/programming-blog\/"},{"@type":"ListItem","position":2,"name":"Environment Variables: Secure Your Python Secrets"}]},{"@type":"WebSite","@id":"https:\/\/www.tonybhimani.com\/programming-blog\/#website","url":"https:\/\/www.tonybhimani.com\/programming-blog\/","name":"Tony's Programming Blog and Development Journal","description":"Sharing is caring... Especially with code","publisher":{"@id":"https:\/\/www.tonybhimani.com\/programming-blog\/#\/schema\/person\/036db10e4bc2069453a60f580f91ab88"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.tonybhimani.com\/programming-blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.tonybhimani.com\/programming-blog\/#\/schema\/person\/036db10e4bc2069453a60f580f91ab88","name":"Tony","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/ed5a2a00dc5d9679e1fd2f29f60ca885a8e0f9d2c1aa2b5dabf05af02663b46c?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/ed5a2a00dc5d9679e1fd2f29f60ca885a8e0f9d2c1aa2b5dabf05af02663b46c?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ed5a2a00dc5d9679e1fd2f29f60ca885a8e0f9d2c1aa2b5dabf05af02663b46c?s=96&r=g","caption":"Tony"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/ed5a2a00dc5d9679e1fd2f29f60ca885a8e0f9d2c1aa2b5dabf05af02663b46c?s=96&r=g"},"sameAs":["https:\/\/tonybhimani.com\/programming-blog","https:\/\/x.com\/TonyBhimani","https:\/\/www.youtube.com\/tonybhimani"],"url":"https:\/\/www.tonybhimani.com\/programming-blog\/author\/coding_magik\/"}]}},"_links":{"self":[{"href":"https:\/\/www.tonybhimani.com\/programming-blog\/wp-json\/wp\/v2\/posts\/210","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tonybhimani.com\/programming-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tonybhimani.com\/programming-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tonybhimani.com\/programming-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tonybhimani.com\/programming-blog\/wp-json\/wp\/v2\/comments?post=210"}],"version-history":[{"count":13,"href":"https:\/\/www.tonybhimani.com\/programming-blog\/wp-json\/wp\/v2\/posts\/210\/revisions"}],"predecessor-version":[{"id":225,"href":"https:\/\/www.tonybhimani.com\/programming-blog\/wp-json\/wp\/v2\/posts\/210\/revisions\/225"}],"wp:attachment":[{"href":"https:\/\/www.tonybhimani.com\/programming-blog\/wp-json\/wp\/v2\/media?parent=210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tonybhimani.com\/programming-blog\/wp-json\/wp\/v2\/categories?post=210"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tonybhimani.com\/programming-blog\/wp-json\/wp\/v2\/tags?post=210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}