Skip to main content

Python dotenv adapter that loads dotenv key value pairs from Azure Developer CLI (azd)

Project description

dotenv-azd

PyPI - Version PyPI - Status PyPI - Python Version PyPI - Downloads

dotenv-azd allows seamless integration of Azure Developer CLI (azd) environment variables into your Python applications without the need to manually export them to an .env file. This can greatly enhance productivity and reduce potential errors, allowing for a smoother development experience.

It leverages the azd CLI and the python-dotenv library.

Why dotenv-azd

Integrating azd environment variables directly into your Python applications can streamline your development process. By avoiding the manual export to .env files, you can reduce overhead and minimize mistakes. This is especially useful when switching between different azd environments.

Installation

pip install dotenv-azd

Usage

Basic Usage

Create a new AZD env if you don't have one yet and set an initial variable value:

azd init MY_AZD_ENV
azd env set VAR1 OVERRIDE

In your Python code:

from dotenv_azd import load_azd_env
from os import getenv, environ

environ['VAR1'] = 'INITIAL'

load_azd_env()

print(getenv('AZURE_ENV_NAME')) # prints 'MY_AZD_ENV', loaded from azd env

print(getenv('VAR1')) # prints 'INITIAL', was already in Python env

Override mode

You can also override variables in Python env:

load_azd_env(override=True)
print(getenv('VAR1')) # prints 'OVERRIDE', loaded from azd env, overriding Python env

Quiet mode

If you want to ignore errors when azd is not initialized or no azd environment is active, you can use the quiet parameter. This is useful when integrating with azd while avoiding dependency on it.

load_azd_env(quiet=True)

Alternatives

The traditional approach to integrate azd environment variables is to export them to a .env file and load that file:

azd env get-values > .env

This approach can create variable quoting issues and might lead to stale variables when switching between environments using azd select.

Contributing

Make a PR to the repo. Run hatch fmt --check to make sure the code is correctly linted.

License

dotenv-azd is distributed under the terms of the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dotenv_azd-0.3.0.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dotenv_azd-0.3.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file dotenv_azd-0.3.0.tar.gz.

File metadata

  • Download URL: dotenv_azd-0.3.0.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for dotenv_azd-0.3.0.tar.gz
Algorithm Hash digest
SHA256 6905c9b7f57e795d66eccb3951814fc62c53fa1d0b22574ee1f726565e543026
MD5 5d9ab8c531974192f365329f1599cc70
BLAKE2b-256 619561a3b01f6fccd2b3d4df619ecb91e986f88eedf18cf6ab4799cf21cf7025

See more details on using hashes here.

File details

Details for the file dotenv_azd-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: dotenv_azd-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for dotenv_azd-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 db57c4cba883662f23a64d86bc3dd1bdf91bcbf13f6452d3db4c156c203657a4
MD5 814135d1b9c2ce7ca8376b9965bb753d
BLAKE2b-256 c1f635a119a3dcfc8995542fee35c83e800a144890337c9a8377d22a2052fa1d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page