skillfed

first

Return the first true value of an iterable.

first v2.0.2 785.1K downloads/30d#5,069 on PyPI156
Permissive license MIT Active released

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 first

uv

uv add first

poetry

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 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseNatural Language :: EnglishOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 2Programming Language :: Python :: 2.6Programming Language :: Python :: 2.7Programming Language :: Python :: 3Programming Language :: Python :: 3.3Programming Language :: Python :: 3.4Programming Language :: Python :: 3.5Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Software Development :: Libraries :: Python Modules

Tags

first true value from iterableget first matching elementfilter and return firstiterable first elementconditional first matchfirst truthy valueselect first from sequence
iteration-utilityfunctional-programming

More Python Modules packages