first
Return the first true value of an iterable.
What it is and what it does
first is a minimal utility that extracts the first truthy value from an iterable, returning None (or a specified default) if no such value exists. It solves a common Python pattern that would otherwise require awkward constructs like next(filter(...)) or generator expressions with conditional logic.
The package provides a single function with three parameters: the iterable to search, an optional key function to customize how truthiness is evaluated (similar to how sorted() uses key), and an optional default to return when no true value is found. It has no dependencies and works across Python 2 and 3 implementations, making it a drop-in replacement for verbose iteration patterns, particularly useful in regex matching chains or filtering operations where readability matters.
Use it for:
- Extract the first matching regex result from multiple compiled patterns without nested conditionals or repeated match calls.
- Find the first non-empty or non-zero value in a sequence of candidates with a single readable function call.
- Select the first element satisfying a custom condition (e.g., first even number) using a key function instead of filter + next.
- Provide a fallback value when iterating through optional results that may all be falsy.
- Simplify common patterns in data validation pipelines where you need the first valid or non-null result.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Returns the first true value from an iterable, with optional key function for custom selection logic and default fallback value.
Yes. This is a stable, MIT-licensed utility with zero dependencies and low install friction. It solves a genuine readability problem in Python iteration patterns. Use it when you find yourself writing next(filter(...)) or generator comprehensions with conditionals—first() is clearer and more Pythonic. The 2019 release date is not a concern given the code's simplicity and the active repository.
Install
first on PyPI
pip
pip install firstuv
uv add firstpoetry
poetry add firstInstalling first
Before you install
Low friction: pure Python, no runtime dependencies, and actively maintained with recent commits. Last release was 2019-03-07, but repository shows ongoing activity as of 2026-03-15.
License in practice
MIT license is permissive; you can use, modify, and distribute this package freely in commercial or private projects with minimal restrictions.
Quickstart
from first import first
# Basic usage
result = first([0, None, False, [], (), 42])
print(result) # Output: 42
# With key function
result = first([1, 1, 3, 4, 5], key=lambda x: x % 2 == 0)
print(result) # Output: 4
# With default
result = first([0, None, False, [], ()], default=42)
print(result) # Output: 42
Verify before relying
- Whether the package is actively maintained beyond the 2019 release date, despite recent repository commits.
Package facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 2,717 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 785,098/month — #5,069 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: first-2.0.2-py2.py3-none-any.whl
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
nr-streamProvides functional-style utilities for Python…
permissive · top 15,000 on PyPI
iterfzfProvides a Python interface to fzf, a…
copyleft · top 15,000 on PyPI
iterproxyWraps any iterable object to provide ORM-style…
permissive · top 5,000 on PyPI
real-regexA drop-in replacement for Python's `re` module…
permissive · top 15,000 on PyPI
pipePipe enables shell-like infix syntax for…
permissive · top 15,000 on PyPI
fuzzysearchFinds approximate substring matches in text or…
permissive · top 15,000 on PyPI
simpleevalEvaluates mathematical and logical expressions…
permissive · top 5,000 on PyPI
google-re2A drop-in replacement for Python's re module…
permissive · top 5,000 on PyPI
seqlogSeqLog sends Python log records to Seq, a…
permissive · top 15,000 on PyPI