--- id: first version: "2.0.2" license: MIT license_treatment: permissive maintenance: active --- # first — Return the first true value of an iterable. License: permissive · Maintenance: active · Downloads: 785.1K/mo ## 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 above — 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 pip install first uv add first poetry add first ## Installing 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: unspecified - Install friction: low - Maintenance: active - Downloads: 785.1K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags first true value from iterable, get first matching element, filter and return first, iterable first element, conditional first match, first truthy value, select first from sequence, iteration-utility, functional-programming [View on SkillFed](https://skillfed.io/packages/first) · [View on PyPI](https://pypi.org/project/first/)