Install & Compatibility
Where this runs
tested against v3.1.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.5MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 2.4s · import 0.000s · 20MB
17MB installed
● package 17MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
FLAGS
✓ import gflags
✗ from gflags import FLAGS
Defines two flags (`name` and `age`) and a boolean `debug` flag. It then parses command-line arguments and prints a greeting. Run with `python your_script.py --name=Python --age=10 --debug`.
import sys
import gflags as flags
FLAGS = flags.FLAGS
flags.DEFINE_string('name', 'World', 'Your name.')
flags.DEFINE_integer('age', 30, 'Your age in years.', lower_bound=0)
flags.DEFINE_boolean('debug', False, 'Enable debug output.')
def main(argv):
try:
argv = FLAGS(argv)
except flags.FlagsError as e:
print(f'{e}\nUsage: {sys.argv[0]} ARGS\n{FLAGS}')
sys.exit(1)
if FLAGS.debug:
print(f'Debug mode enabled. Non-flag arguments: {argv}')
print(f'Hello, {FLAGS.name}! You are {FLAGS.age} years old.')
if __name__ == '__main__':
main(sys.argv)
Debug
Known issues
breakingThe entire `python-gflags` library is deprecated and no longer actively maintained. All new development has moved to `absl-py`, specifically `absl.flags`. Users should plan to migrate to `absl-py` to receive updates and avoid unmaintained dependencies.fixMigrate your codebase to use `absl-py`. The `python-gflags` 3.1.2 release included API name changes to ease compatibility. Refer to the `absl-py` migration guidelines.
affects: 3.1.2 onwards
breakingVersion 3.1.0 introduced significant breaking changes, including: removal of `UnrecognizedFlag` (now `UnparsedFlagAccessError` can be raised for premature flag access), replacement of `DuplicateFlag` with `DuplicateFlagError`, renaming of `IllegalFlagValue` to `IllegalFlagValueError`, and moving `validators.Error` to `exceptions.ValidationError`. Several methods like `MutualExclusionValidator`, `FlagValues.AddValidator`, and `_helpers.GetMainModule` were removed.fixUpdate exception handling and API calls according to the new naming conventions and removed functionality. Consult the GitHub release notes for 3.1.0 and absl migration guide.
affects: >=3.1.0
gotchaIf `python-gflags` and `absl.flags` are both present in the same process, it can lead to two global `FLAGS` objects coexisting, causing unexpected behavior and conflicts during flag definition and parsing.fixEnsure that your project and its dependencies are consistently using either `python-gflags` or `absl-py`, but not both. Prioritize migrating to `absl-py`.
affects: All versions when used alongside `absl-py`
gotchaAccessing flag values before command-line arguments have been parsed by calling `FLAGS(sys.argv)` can raise an `UnparsedFlagAccessError` in newer versions. Additionally, `FLAGS.set_default` no longer overrides the current value if the flag has already been set via command line or direct assignment.fixAlways ensure `FLAGS(sys.argv)` is called early in your application's lifecycle before attempting to access any flag values. Be aware of the new `FLAGS.set_default` behavior.
affects: >=3.1.0 (for UnparsedFlagAccessError); >=3.0.5 (for set_default behavior)
Upgrade
Version history
3.1.2latest on PyPI · released Oct 27, 2017
Audit
Dependencies
No dependency data recorded yet.