{"id":6834,"library":"python-gflags","title":"Python Gflags","description":"Python-gflags is a Python implementation of the Google command-line flags module, enabling distributed command-line systems by allowing flags to be defined across different modules. It is currently at version 3.1.2. This library is now obsolete and no longer maintained; users are strongly encouraged to migrate to `absl-py` for continued support and new features.","status":"deprecated","version":"3.1.2","language":"en","source_language":"en","source_url":"https://github.com/google/python-gflags","tags":["command-line-parsing","flags","cli","deprecated"],"install":[{"cmd":"pip install python-gflags","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"While `from gflags import FLAGS` works, the idiomatic and safer way is to import `gflags` as `flags` and then assign `FLAGS = flags.FLAGS` to avoid potential naming conflicts and clearly denote where FLAGS originates.","wrong":"from gflags import FLAGS","symbol":"FLAGS","correct":"import gflags as flags\nFLAGS = flags.FLAGS"},{"symbol":"DEFINE_string","correct":"import gflags as flags\nflags.DEFINE_string('name', 'default', 'help string')"},{"symbol":"DEFINE_integer","correct":"import gflags as flags\nflags.DEFINE_integer('count', 0, 'help string')"}],"quickstart":{"code":"import sys\nimport gflags as flags\n\nFLAGS = flags.FLAGS\n\nflags.DEFINE_string('name', 'World', 'Your name.')\nflags.DEFINE_integer('age', 30, 'Your age in years.', lower_bound=0)\nflags.DEFINE_boolean('debug', False, 'Enable debug output.')\n\ndef main(argv):\n    try:\n        argv = FLAGS(argv)\n    except flags.FlagsError as e:\n        print(f'{e}\\nUsage: {sys.argv[0]} ARGS\\n{FLAGS}')\n        sys.exit(1)\n\n    if FLAGS.debug:\n        print(f'Debug mode enabled. Non-flag arguments: {argv}')\n\n    print(f'Hello, {FLAGS.name}! You are {FLAGS.age} years old.')\n\nif __name__ == '__main__':\n    main(sys.argv)","lang":"python","description":"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`."},"warnings":[{"fix":"Migrate 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.","message":"The 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.","severity":"breaking","affected_versions":"3.1.2 onwards"},{"fix":"Update 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.","message":"Version 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.","severity":"breaking","affected_versions":">=3.1.0"},{"fix":"Ensure that your project and its dependencies are consistently using either `python-gflags` or `absl-py`, but not both. Prioritize migrating to `absl-py`.","message":"If `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.","severity":"gotcha","affected_versions":"All versions when used alongside `absl-py`"},{"fix":"Always 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.","message":"Accessing 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.","severity":"gotcha","affected_versions":">=3.1.0 (for UnparsedFlagAccessError); >=3.0.5 (for set_default behavior)"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}