Abseil Python Common Libraries
raw JSON → 2.4.0 verified Tue May 12 auth: no python install: verified quickstart: verified
absl-py is a collection of Python library code for building Python applications, originating from Google's internal codebase. It provides essential utilities for application startup, a distributed command-line flags system, a custom logging module, and testing utilities. The library is actively maintained, with frequent releases, and is currently at version 2.4.0.
pip install absl-py Common errors
error ModuleNotFoundError: No module named 'absl' ↓
cause The 'absl-py' package is not installed in the Python environment.
fix
Install the package using 'pip install absl-py'.
error ImportError: No module named absl.flags ↓
cause The 'absl-py' package is not installed or is installed in a different Python environment.
fix
Ensure 'absl-py' is installed in the correct environment using 'pip install absl-py'.
error ImportError: No module named absl.testing ↓
cause The 'absl-py' package is not installed or is installed in a different Python environment.
fix
Ensure 'absl-py' is installed in the correct environment using 'pip install absl-py'.
error ImportError: No module named 'absl' ↓
cause The 'absl-py' package is not installed or is installed in a different Python environment.
fix
Ensure 'absl-py' is installed in the correct environment using 'pip install absl-py'.
error absl.flags._exceptions.UnparsedFlagAccessError: Trying to access flag --[flag_name] before flags were parsed. ↓
cause A flag defined using `absl.flags` is being accessed before `absl.app.run()` has been called or before `absl.flags.FLAGS(sys.argv)` has explicitly parsed the command-line arguments.
fix
Ensure
app.run(main) is called at the entry point of your script, or explicitly parse flags with FLAGS(sys.argv) before accessing them. Example: from absl import app, flags; FLAGS = flags.FLAGS; flags.DEFINE_string('my_flag', 'default', 'My flag.'); def main(argv): print(FLAGS.my_flag); if __name__ == '__main__': app.run(main) Warnings
breaking Abseil Python has progressively dropped support for older Python versions. Version 2.4.0 dropped support for Python 3.8 and 3.9. Version 2.2.2 removed support for Python 3.7. Version 2.0.0 dropped support for Python 3.6. ↓
fix Ensure your Python environment is version 3.10 or newer to use the latest `absl-py` versions.
gotcha Directly evaluating `absl.flags.Flag` instances in a boolean context (e.g., `if FLAGS.myflag:`) will raise an error. This prevents accidental usage of the Flag object itself rather than its value. ↓
fix Always access the flag's value using the `.value` attribute: `if FLAGS.myflag.value:`.
breaking The `absl.logging.exception` function's behavior regarding the `exc_info` argument changed in v2.0.0. Previously, passing `exc_info` could raise a `KeyError`. It now correctly accepts `exc_info` as an argument (with a default value of `True`). ↓
fix If your code explicitly passes `exc_info` to `logging.exception`, ensure `absl-py` is version 2.0.0 or higher. Otherwise, verify behavior on older versions if `exc_info` is relied upon.
gotcha Flag names defined with `absl.flags.DEFINE_*` are globally registered. This means that if multiple modules or libraries define flags with the same name, a `DuplicateFlagError` will occur upon import or flag definition. ↓
fix Choose unique and descriptive flag names, especially in larger applications or when integrating multiple libraries. For more advanced isolation, consider managing flags with separate `flags.FlagValues` instances, though this is less common for standard usage.
Install compatibility verified last tested: 2026-05-12
python os / libc status wheel install import disk
3.10 alpine (musl) wheel - 0.19s 18.7M
3.10 alpine (musl) - - 0.22s 18.7M
3.10 slim (glibc) wheel 1.5s 0.13s 19M
3.10 slim (glibc) - - 0.13s 19M
3.11 alpine (musl) wheel - 0.30s 20.7M
3.11 alpine (musl) - - 0.34s 20.7M
3.11 slim (glibc) wheel 1.6s 0.25s 21M
3.11 slim (glibc) - - 0.24s 21M
3.12 alpine (musl) wheel - 0.30s 12.6M
3.12 alpine (musl) - - 0.32s 12.6M
3.12 slim (glibc) wheel 1.5s 0.30s 13M
3.12 slim (glibc) - - 0.31s 13M
3.13 alpine (musl) wheel - 0.35s 12.3M
3.13 alpine (musl) - - 0.32s 12.2M
3.13 slim (glibc) wheel 1.5s 0.29s 13M
3.13 slim (glibc) - - 0.30s 13M
3.9 alpine (musl) wheel - 0.19s 18.2M
3.9 alpine (musl) - - 0.21s 18.2M
3.9 slim (glibc) wheel 1.7s 0.15s 19M
3.9 slim (glibc) - - 0.16s 19M
Imports
- app
from absl import app - flags
from absl import flags - logging
from absl import logging - absltest
from absl.testing import absltest - flagsaver
from absl.testing import flagsaver
Quickstart verified last tested: 2026-04-23
from absl import app
from absl import flags
from absl import logging
import os
FLAGS = flags.FLAGS
flags.DEFINE_string('greeting_target', 'World', 'The entity to greet.')
flags.DEFINE_integer('repeat_count', 1, 'How many times to repeat the greeting.', lower_bound=1)
flags.DEFINE_boolean('verbose', False, 'If true, print verbose output.')
def main(argv):
if FLAGS.verbose:
logging.set_verbosity(logging.DEBUG)
logging.debug('Verbose mode enabled. Non-flag arguments: %s', argv[1:])
else:
logging.set_verbosity(logging.INFO)
for _ in range(FLAGS.repeat_count):
logging.info('Hello, %s!', FLAGS.greeting_target)
# Example of an argument passed directly, not as a flag
if len(argv) > 1:
logging.warning('Unrecognized positional arguments: %s', argv[1:])
if __name__ == '__main__':
# To run: python your_script.py --greeting_target=User --repeat_count=3 --verbose
# Or with environment variable for testing:
# os.environ['greeting_target'] = 'TestUser'
# os.environ['repeat_count'] = '2'
# Then run: python your_script.py --verbose
app.run(main)