January 2021 Summaries
2 posts from Doppler
Filter
Month:
Year:
Post Summaries
Back to Blog
Environment variables are a powerful way to configure applications, offering benefits such as deploying without code changes, ensuring secrets are not leaked into source code, and abstracting config and secret supply. In Python, environment variables can be accessed using the `os.environ` object, which acts like a dictionary but has limitations. To get an environment variable, you can access it directly, use the `get()` method with a default value, or check for its existence without caring about its value. You can set environment variables in Python just like setting keys on a dictionary, and there are libraries available to parse `.env` files and populate the `os.environ` object, but these have drawbacks such as security issues and difficulties with managing them across environments. A more recommended approach is using a centralized config solution like Doppler, which provides an access-controlled dashboard for managing environment variables and offers benefits such as type checking and typecasting, making it easier to work with configuration values in your codebase.
Jan 21, 2021
1,926 words in the original blog post.
Environment variables are values that control the behavior of operating systems, individual utilities like Git, shell scripts, user applications such as the Google Chrome browser, or deployed applications like a Python web app. They can be set using commands like `export` and accessed using `$`. Shell variables have local scope, while environment variables have global scope. Environment variables are designed to be accessible to scripts or child processes, whereas shell variables are only accessible in the current shell. To change an environment variable, use `export`, and to delete one, use `unset`. Variable names should follow a specific syntax and convention. Environment variables can be used to capture output from commands, avoid spaces around equals signs, and quote values to prevent word-splitting issues. They are also useful for supplying config and secrets to deployed applications and configuring CI/CD jobs and environments. To execute a script in the context of the current shell, prefix it with a leading period (`.`). When using `sudo`, use the `--preserve-env` flag to pass through environment variables from the current shell. Additionally, there are resources available for further learning on shell programming, such as Bite Size Bash and Shellcheck static analysis tool.
Jan 08, 2021
2,539 words in the original blog post.