---
source: https://iinventedlight.com/library/notes/python-os-environ.md
title: "os.environ is a string mapping of the process environment, captured at import"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "PSF-2.0 (Python docs); PSF-2.0 (python/cpython (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Python docs, os — Miscellaneous operating system interfaces (environ), PSF-2.0 (https://docs.python.org/3/license.html); python/cpython (GitHub), os.rst environ and getenv (CPython docs), PSF-2.0 (https://raw.githubusercontent.com/python/cpython/main/LICENSE)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-17
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-17
as_of: 2026-11-17
confidence: medium
untested: "Not reproduced (2026-11-17). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-python: os.environ and getenv"
tags: [python, os, environ, getenv, environment]
client: Librarian
sources:
  - id: S1
    title: "os — Miscellaneous operating system interfaces (environ)"
    publisher: Python docs
    url: https://docs.python.org/3/library/os.html
    accessed: 2026-11-17
    license: "PSF-2.0"
  - id: S2
    title: "os.rst environ and getenv (CPython docs)"
    publisher: python/cpython (GitHub)
    url: https://github.com/python/cpython/blob/main/Doc/library/os.rst
    accessed: 2026-11-17
    license: "PSF-2.0"
---
# os.environ is a string mapping of the process environment, captured at import
**Answer:** `os.environ` is a mapping whose keys and values are strings that represent the process environment. The mapping is captured the first time the `os` module is imported. Changes made to the environment after that point are not reflected in `os.environ`, except for changes made by modifying `os.environ` itself.

## Writing values and getenv

You can query or modify the environment through this mapping. `putenv()` will be called automatically when the mapping is modified. On Windows, keys are converted to uppercase. Deleting an item unsets the variable and calls `unsetenv()`.

`os.getenv(key, default=None)` returns that variable's string value when the key exists, otherwise `default`. Because `getenv` uses `os.environ`, it is also captured on import and may not reflect later environment changes made outside this mapping.

## See also

- [python-pathlib](https://iinventedlight.com/library/notes/python-pathlib/)
- [python-venv](https://iinventedlight.com/library/notes/python-venv/)

## Claims

- id: C1
  claim: os.environ is captured the first time the os module is imported.
  source: S1
  evidence: "This mapping is captured the first time the"

- id: C2
  claim: On Windows, environ keys are converted to uppercase.
  source: S1
  evidence: "keys are converted to uppercase"

- id: C3
  claim: os.environ is a mapping of string keys and values for the process environment.
  source: S2
  evidence: "mapping` object where keys and values are strings"

- id: C4
  claim: getenv returns the environment variable key as a string, or a default.
  source: S2
  evidence: "Return the value of the environment variable *key* as a string"

## Sources

- [S1] os — Miscellaneous operating system interfaces (environ). Python docs. https://docs.python.org/3/library/os.html . License: PSF-2.0. Accessed 2026-11-17.

- [S2] os.rst environ and getenv (CPython docs). python/cpython (GitHub). https://github.com/python/cpython/blob/main/Doc/library/os.rst . License: PSF-2.0. Accessed 2026-11-17.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python docs, os — Miscellaneous operating system interfaces (environ), PSF-2.0 (https://docs.python.org/3/license.html); python/cpython (GitHub), os.rst environ and getenv (CPython docs), PSF-2.0 (https://raw.githubusercontent.com/python/cpython/main/LICENSE). Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
