Skip to content

feat: Add support for environment variable configuration (#634)#657

Open
unseen2004 wants to merge 1 commit intogoogle:masterfrom
unseen2004:master
Open

feat: Add support for environment variable configuration (#634)#657
unseen2004 wants to merge 1 commit intogoogle:masterfrom
unseen2004:master

Conversation

@unseen2004
Copy link
Copy Markdown

 ### Summary
 This PR implements support for configuring Python Fire CLIs via environment variables, addressing issue #634. It allows users to pass configuration
  values securely (e.g., API keys) without exposing them in process lists.

 ### Key Features
 - **Naming Convention**: Parameters can be specified using `FIRE_<PARAM_NAME>` (e.g., `export FIRE_NAME=World`).
 - **Broad Support**: Works for positional arguments, keyword-only arguments, and `**kwargs`.
 - **Precedence**: Command-line arguments (flags/positional) correctly take precedence over environment variables.
 - **Type Safety**: Values from environment variables are parsed as Python literals (int, bool, list, etc.), matching standard Fire behavior.

### Changes
- **Logic**: Updated `fire/core.py` to include environment variable lookup during argument parsing.
- **Tests**: Added `fire/env_config_test.py` with 100% coverage for the new feature (including override and type parsing scenarios).
- **Docs**: Updated `docs/guide.md` and `docs/using-cli.md` with instructions and examples.

### Verification
- Verified by running the complete test suite (277 tests passed).
- Adheres to the Google Python Style Guide and project-specific conventions:
- PascalCase for methods.
- 2-space indentation.
- Single quotes for strings.

Allows configuration values to be read from environment variables using
the FIRE_<PARAM_NAME> naming convention. Supports positional arguments,
keyword-only arguments, and **kwargs. CLI arguments continue to take
precedence over environment variables.

Includes documentation and tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant