---
title: "envier | pypx"
description: "Python application configuration via the environment"
canonical_url: "https://pypx.app/packages/envier"
meta:
  "og:description": "Python application configuration via the environment"
  "og:image": "https://pypx.app/_og/d/h_630%2Cc_PackageCard%2Cname_envier%2Cversion_0.6.1%2Csummary_Python%2Bapplication%2Bconfiguration%2Bvia%2Bthe%2Benvironment%2Clicense_MIT%2BLicense%2Cp_Ii9wYWNrYWdlcy9lbnZpZXIi%2Cs_sjbnntNtVGaR95wC.png"
  "og:image:height": "630"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "envier 0.6.1"
  "twitter:image": "https://pypx.app/_og/d/h_630%2Cc_PackageCard%2Cname_envier%2Cversion_0.6.1%2Csummary_Python%2Bapplication%2Bconfiguration%2Bvia%2Bthe%2Benvironment%2Clicense_MIT%2BLicense%2Cp_Ii9wYWNrYWdlcy9lbnZpZXIi%2Cs_sjbnntNtVGaR95wC.png"
---

> Index of every page on this site: [llms.txt](https://pypx.app/llms.txt)

# **envier**

v0.6.1

Python application configuration via the environment

10 KB Python 3.7+ py3-none-anyMIT License Possibly Unmaintained

[** Diff **](https://pypx.app/packages/envier/diff)

`$ uv add envier`

## Synopsis

Envier is a Python library for extracting configuration from environment variables in a declarative and (eventually) 12-factor-app-compliant way.

## Usage

The following example shows how to declare the configuration for an application that uses the `MYAPP_DEBUG`, `MYAPP_SERVICE_HOST` and `MYAPP_SERVICE_PORT` variables from the environment.

```
>>> from envier import Env
>>> 
>>> class GlobalConfig(Env):
>>>     __prefix__ = "myapp"
>>>     
>>>     debug_mode = Env.var(bool, "debug", default=False)
>>> 
>>>     service_host = Env.var(str, "service.host", default="localhost")
>>>     service_port = Env.var(int, "service.port", default=3000)
>>> 
>>>     _is_default_port = Env.der(bool, lambda c: c.service_port == c.spec.service_port.default)
>>> 
>>> config = GlobalConfig()
>>> config.service_port
3000
>>> config._is_default_port
True
```

Configurations can also be nested to create namespaces:

```
>>> from envier import Env
>>> 
>>> class ServiceConfig(Env):
>>>     __prefix__ = "service"
>>> 
>>>     host = Env.var(str, "host", default="localhost")
>>>     port = Env.var(int, "port", default=3000)
>>> 
>>> class GlobalConfig(Env):
>>>     __prefix__ = "myapp"
>>>     
>>>     debug_mode = Env.var(bool, "debug", default=False)
>>> 
>>>     service = ServiceConfig
>>> 
>>> config = GlobalConfig()
>>> config.service.port
3000
```

The same configuration can be obtained with implicit nesting by declaring the `ServiceConfig` subclass inside `GlobalConfig`, and setting the class attribute `__item__` to the name of the item the sub-configuration should be assigned to, viz.

```
>>> from envier import Env
>>> 
>>> class GlobalConfig(Env):
>>>     __prefix__ = "myapp"
>>>     
>>>     debug_mode = Env.var(bool, "debug", default=False)
>>> 
>>>     class ServiceConfig(Env):
>>>         __item__ = __prefix__ = "service"
>>>         
>>>         host = Env.var(str, "host", default="localhost")
>>>         port = Env.var(int, "port", default=3000)
>>> 
>>> config = GlobalConfig()
>>> config.service.port
3000
```

## Type Checking

The library ships with a `mypy` plugin to allow for type checking. If you want to use it, either install the library with the `mypy` extra or ensure that `mypy` is installed, and then add `envier.mypy` to the list of extra plugins in the `mypy` configuration.

## Roadmap

- Add support for environment files.
- Rely on type hints as support for older versions of Python is dropped.
- Derivations might require an evaluation order.

## **Details **

<dl>

<dt>Version</dt>
<dd>0.6.1</dd>

<dt>License</dt>
<dd>MIT License</dd>

<dt>Python</dt>
<dd>&gt;=3.7</dd>

<dt>Maintainer</dt>
<dd>Datadog &lt;dev@datadoghq.com&gt;</dd></dl>

## **Links**

- [Homepage](https://github.com/DataDog/envier)
- [View on PyPI](https://pypi.org/project/envier/)

## **Maintainers **

- Datadog · [dev@datadoghq.com](mailto:dev@datadoghq.com)

```json
{"@context":"https://schema.org","@graph":[{"@id":"https://pypx.app/#website","@type":"WebSite","description":"The Python Package Index, reimagined. Fast search, dependency insights, download trends, and changelogs — all in one place.","name":"pypx","url":"https://pypx.app/"},{"@id":"https://pypx.app/packages/envier#webpage","@type":"WebPage","description":"Python application configuration via the environment","name":"envier","url":"https://pypx.app/packages/envier","isPartOf":{"@id":"https://pypx.app/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://pypx.app/packages/envier"]}]},{"@id":"https://pypx.app/packages/envier#/schema/software-application/1","@type":"SoftwareApplication","applicationCategory":"DeveloperApplication","description":"Python application configuration via the environment","license":"MIT License","name":"envier","softwareVersion":"0.6.1"}]}
```

## Sitemap

See the full [sitemap](https://pypx.app/sitemap.md) for all pages.
