Bug fixes:
- Exported environment variables take precedence over
.envfiles (regression from 15.0.0) (#464). Thanks DougEdey-Slice for reporting.
Features:
Env.read_envno longer mutatesos.environ(#393). Values from.envfiles are loaded into theEnvinstance only. This comes with two breaking changes:Env.read_envis now an instance method rather than a@staticmethod.Env.read_env()->env.read_env()- The
verboseparameter ofread_envis been removed.
Other changes:
- Drop support for marshmallow 3, which is EOL. marshmallow>=4.0.0 is supported.
- Minor typing improvements (#463).
Bug fixes:
- Fix variable expansion with other characters (#359). Thanks flymanzhao for reporting and veeceey for the PR.
Other changes:
Features:
- Add
strip_whitespaceparam toFileAwareEnv(#431). Thanks eandersons for the suggestion and PR.
Other changes:
- Drop support for Python 3.9, which is EOL.
Features:
- Add support for ISO 8601 durations to
env.timedelta. (#434). Thanks lucas-bremond for the suggestion and PR.
Features:
- Add
environs.FileAwareEnvfor reading secret files (#410). Thanks holtgrewe for the suggestion. Thanks whyscream and avilaton for the PRs.
Features:
Bug fixes:
- Typing: Fix typing for
env.listandenv.dictto properly handledefaultandsubcastarguments (#406). Thanks lucas-bremond for the PR. - Add
envto__all__(#396). Thanks daveflr for reporting.
Changes:
- Backwards-incompatible:
recurse,verbose,override, andreturn_pathparameters toEnv.read_envare now keyword-only. - Backwards-incompatible: The
requiredargument to parser methods is removed. Call a parser method without a default value to make it required.
Features:
- Add
prefixparameter toEnvconstructor (#384). Thanks arthurc0102 for the suggestion. - Re-export
validatemodule from marshmallow (#385).
Bug fixes:
- Typing: Fix typing for
Env.enumto allowby_valueto be passed (#386).
Features:
- Add
envsingleton ([#194]). Thanks AndBondStyle for the suggestion.
from environs import envChanges:
defaultvalues are expected to be their in their deserialized form. Backwards-incompatible: Passing serialized values todefaultis no longer supported.
from datetime import date, timedelta
import environs
# DO
enable_login = env.bool("ENABLE_LOGIN", True)
ttl = env.timedelta("TTL", default=timedelta(seconds=600))
release_date = env.date("RELEASE", date(2025, 1, 7))
numbers = env.list("FOO", [1.0, 2.0, 3.0], subcast=float)
# DON'T
enable_login = env.bool("ENABLE_LOGIN", "true")
ttl = env.timedelta("TTL", default=600)
release_date = env.date("RELEASE", "2025-01-07")
numbers = env.list("NUMBERS", "1,2,42", subcast=float)The exceptions to this rule are the Django-related functions, which accept string defaults.
DATABASE_URL = env.dj_db_url("DATABASE_URL", default="postgresql://localhost:5432/mydb")Features:
- Typing: Add type hints for parser methods (#367). Thanks OkeyDev for the PR.
- Add
by_valueparam toEnv.enum. Passby_value=Trueto parse Enum by values instead of names.
Other changes:
- Drop support for marshmallow<3.18.0.
- Backwards-incompatible: Remove
load_defaultparam from parser methods. Usedefaultinstead. - Backwards-incompatible: Rename
Env.enum'stypeparam toenum. - Backwards-incompatible: Remove
ignore_caseparam fromEnv.enum. - Backwards-incompatible: Remove
allow_none,error_messages, andmetadataparams from parser methods.
Features:
Env.enumallows passing anEnumasdefault.
Other changes:
- Support marshmallow 4.
- Support Python 3.9-3.13.
- Backwards-incompatible: Make
Fieldclasses private. Users should not need to access these.
Bug fixes:
- Fix passing non-string default values to
Env.timedelta(#369). Thanks tcleonard for reporting and thanks ddelange for the PR. - Fix
Env.read_env(recurse=True)so that it returns as soon as a.envfile is found (#370). Thanks senese for the PR.
Features:
Features:
- Add
return_pathargument toEnv.read_envto return the path of the parsed file (#362). Thanks senese for the suggestion and PR. NOTE: This is added as a backwards-compatible change that is scheduled to be removed in 12.0.0. The path will stored as an attribute ofEnv.
Fixes:
- Prevent
DeprecationWarninggetting raised by marshmallow 3.21.0 (:issue:333).
Other changes:
- Remove
subcast_keyargument ofenv.dict. Usesubcast_keysinstead. - Bump minimum required marshmallow version to 3.13.0.
- Remove
missingargument fromEnvmethods. Usedefaultinstead. - Remove
subcastargument fromEnvmethods that don't use it. - Backwards-incompatible: Remove
environs.__version__variable. Useimportlib.metadata.version("environs")instead.
Features:
Env.__repr__andEnv.__str__no longer display environment variables, to prevent accidental exfiltration of sensitive data (#292). Thanks mro-rhansen2 for the suggestion.
Bug fixes:
- Fix passing
Noneas default toenv.list(#298). Thanks lucas-bremond for reporting.
Features:
Features:
Other changes:
- Test against Python 3.12.
Features:
- Add
delimiterargument toenv.dict(#277). Thanks gregoiredx for the PR.
Other changes:
- Backwards-incompatible: Drop support for EOL Python 3.6 and 3.7.
- Test against Python 3.11.
- Migrate to setup.cfg. Thanks deronnax for the PR.
Features:
- Allow callables or custom marshmallow fields to be passed to
subcast,subcast_keys, andsubcast_values. (#241). Thanks bvanelli for the PR.
Bug fixes:
- Address warning about passing metadata in newer versions of marshmallow.
Other changes:
- Test against Python 3.10.
Bug fixes:
- Fix
env.urland other parsers that take field keyword arguments (#227). Thanks KochankovID for the PR.
Bug fixes:
- Allow default for
env.pathto be apathlib.Path(#228). Thanks KochankovID for the PR.
Bug fixes:
- Fix compatibility with marshmallow>=3.13.0 so that no DeprecationWarnings are raised (#224).
Bug fixes:
Bug fixes:
Deprecations:
- Rename
subcast_keyargument ofenv.dicttosubcast_keysfor consistency withsubcast_values.subcast_keyis deprecated.
Features:
- Add time parser (#191).
Features:
Thanks tomgrin10 for the PRs.
Bug fixes:
- Loosen
ParserMethodtyping (#186 (comment)). Thanks hukkinj1 for the PR.
Other changes:
- When using deferred validation (
eager=False), parser methods returnNonefor missing or invalid values. Note: This may break code that depended on parser methods returningmarshmallow.missing, but this behavior was not documented nor tested and therefore is not considered public API.
- Backwards-incompatible: Rename
subcastparam ofenv.dicttosubcast_valuesfor consistency withsubcast_keys. - Backwards-incompatible: Remove variable proxying. Use variable expansion instead (see 8.1.0 release notes below) (#175).
- Backwards-incompatible: Drop support for marshmallow 2 and Python 3.5, which are both EOL (#174).
Features:
- Add support for variable expansion, e.g.
MY_VAR=${MY_OTHER_VAR:-mydefault}(#164). Thanks gnarvaja for the PR.
Deprecations:
- Variable proxying using the
{{VAR}}syntax is deprecated and will be removed in environs 9.0.0. Use variable expansion using${VAR}instead.
# Before
export MAILGUN_LOGIN=sloria
export SMTP_LOGIN={{MAILGUN_LOGIN}}
# After
export MAILGUN_LOGIN=sloria
export SMTP_LOGIN=${MAILGUN_LOGIN}from environs import Env
env = Env(expand_vars=True)
SMTP_LOGIN = env.str("SMTP_LOGIN") # => 'sloria'Bug fixes:
- Fix deferred validation behavior for
dj_db_url,dj_email_url,dj_cache_url, and custom parsers (#121). Thanks hukkinj1 for reporting.
Other changes:
- Test against Python 3.9.
- Remove usage of implicit
typing.Optional(171).
Bug fixes:
- Fix behavior of recurse=True when custom filepath is passed to
env.read_env(#100). Thanks ribeaud and timoklimmer for the help.
Other changes:
- Backwards-incompatible: As a result of the above fix, passing a directory to
env.read_envis no longer allowed and will raise aValueError. Only file paths or file names should be passed.
- Fix error when parsing empty list with subcast #137. Thanks [sabdouni] for the catch and patch.
log_levelaccepts lower-cased log level names and rejects invalid names (#138). Thanks gnarvaja for the PR.
- Add
dj_cache_urlfor caching Django cache URLs (requires installing with[django]) (#126). Thanks epicserve for the suggestion and PR.
- Improve typings and run mypy with dependencies type annotations (#115).
- Distribute types per PEP 561 (#116).
Thanks hukkinj1 for the PRs.
- Backwards-incompatible: Remove
streamargument fromread_env, since it had no effect (#114). - Backwards-incompatible:
Env.read_envconsistently returnsNone(#111). - Remove unnecessary
__str__definition (#112).
Thanks hukkinj1 for the PRs.
Features:
- Add deferred validation via the
eagerparameter andenv.seal()(#56). Thanks robertlagrant for the suggestion.
Other changes:
- Test against Python 3.8 (#108).
Features:
- Default parser methods are now defined as bound methods. This enables static analysis features, e.g. autocomplete (#103). Thanks rugleb for the suggestion. Backwards-incompatible: As a result of this change, adding a parser name that is the same as an existing method will result in an error being raised.
import environs
env = environs.Env()
# Below conflicts with built-in `url` method.
# In <6.0.0, this would override the built-in method.
# In >=6.0.0, this raises an error:
# environs.ParserConflictError: Env already has a method with name 'url'. Use a different name.
@env.parser_for("url")
def https_url(value):
return "https://" + valueBug fixes:
- Fix error message for prefixed variables (#102). Thanks AGeekInside for reporting.
Other changes:
- Backwards-incompatible: Rename
Env.__parser_map__toEnv.__custom_parsers__.
Bug fixes:
- Fix behavior when recursively searching for a specified file (#96). Thanks ribeaud for the catch and patch.
Changes:
- Improve typings.
Features:
- Add
env.log_level(#7). - Use
raise fromto improve tracebacks.
Other changes:
- Improve typings.
Features:
Other changes:
- Backwards-incompatible: Drop support for Python 2. If you use Python 2, you will need to use version 4.2.0 or older.
- Minor optimization.
Bug fixes:
- Reset prefix when an exception is raised within an
env.prefixed()context (#78). Thanks rcuza for the catch and patch.
Bug fixes:
Support:
- Document how to read a specific file with
env.read_env(#66). Thanks nvtkaszpir and c-w.
Bug fixes:
- Fix compatibility with marshmallow 3.0.0>=rc6.
Bug fixes:
- Fix accessing proxied envvars when using
env.prefixed(#72). Thanks Kamforka for the catch and patch. - Fix behavior when an envvar is explicitly set to an empty string (#71). Thanks twosigmajab for reporting and thanks hvtuananh for the PR.
EnvErrorsubclassesValueError(#50). Thanks alexpirine.- Test against Python 3.7.
- Use python-dotenv for parsing .env files.
Env.read_envbehaves mostly the same except that a warning isn't raised by default if a .env file isn't found. Passverbose=Trueto raise a warning.
Features:
- Backwards-incompatible:
Env.read_envraises a warning instead of an error when.envisn't found (#10). Thanks lachlancooper for the suggestion. - Add optional Django support. Install using
pip install environs[django], which enablesenv.dj_db_urlandenv.dj_email_url.
Features:
- Fix compatibility with marshmallow 3 beta.
Features:
Features:
Other changes:
- Backwards-incompatible: Drop support for Python 3.3 and 3.4.
Features:
- Add
urlparser that returns aurllib.parse.ParseResult(#6). Thanks IlyaSemenov for the suggestion.
Bug fixes:
- Every instance of
Envgets its own parser map, so callingenv.parser_forfor one instance doesn't affect other instances.
- Add
Env.read_envmethod for reading.envfiles.
- Support for proxied variables (#2).
- Backwards-incompatible: Remove
env.getmethod. Useenv()instead. - Document how to read
.envfiles (#1).
- First PyPI release.