environment variable (env var)
An environment variable (env var) is a named value that a running program receives from the system that started it. The program and any programs it launches can read that value at runtime to configure how they behave.
Every process carries its own environment, a set of name-value pairs that the operating system hands down from the parent process that started it.
A child process receives a copy of this set when it is created, so a later change in one process never reaches its parent or its siblings. This copy-on-launch behavior makes the environment a one-way channel for passing settings into a program without altering its command line or its source code.
Launch a child process below, then edit a value in either process to see what the copy carries and what it doesn’t:
Common uses include the following:
- Locating resources, as with
PATH, the list of directories a shell searches for executables, orHOME, which records the current user’s home directory. - Selecting behavior, where a variable such as
LANGorTZswitches locale or time zone without any change to code. - Passing secrets, supplying values like API keys and database URLs to a program so they stay out of version-controlled files.
A variable can be scoped to a single command, a login session, a user account, or the whole system, and a shell sets one with syntax like export NAME=value. Unix-like systems treat the names as case-sensitive, whereas Windows does not. Python reads the current environment through the os module as the os.environ mapping.
Related Resources
Tutorial
Securely Deploy a Django App With Gunicorn, Nginx, & HTTPS
Ready to take your Django app beyond development? Learn how to securely deploy your Django web app in production over HTTPS with Gunicorn and Nginx. Along the way, you'll explore how HTTP headers can fortify your app's security.
For additional information on related topics, take a look at the following resources:
- Continuous Integration and Deployment for Python With GitHub Actions (Tutorial)
- Deploying a Python Flask Example Application Using Heroku (Tutorial)
- Python Command-Line Arguments (Tutorial)
- Python and TOML: Read, Write, and Configure with tomllib (Tutorial)
- Python Virtual Environments: A Primer (Tutorial)
- Deploy a Django App With Gunicorn and Nginx (Course)
- Python Continuous Integration and Deployment Using GitHub Actions (Course)
- GitHub Actions for Python (Quiz)
- Deploying a Flask Application Using Heroku (Course)
- Command Line Interfaces in Python (Course)
- Working With TOML and Python (Course)
- Working With Python Virtual Environments (Course)
- Python Virtual Environments: A Primer (Quiz)
By Martin Breuss • Updated Aug. 12, 2026