lfp-types
Lightweight runtime typing helpers for iterable detection, container normalization, flattening, and bool parsing.
Features
- Runtime Container Type:
Container[T]that excludes string-like values (str, bytes, etc). - Type Guards:
is_iterable,is_container, andis_sequencehelper checks. - Normalization:
to_iterableandto_containerhelpers to handle scalars and collections uniformly. - Flattening: Optional recursive flattening for nested iterables.
- Boolean Parsing:
to_boolparser with support for common truthy and falsy string/numeric values. - Type Variables: Public
TypeVarexports forAthroughZ.
Install
pip install lfp-types
Usage
Iterable and Container Checks
Check if a value is a non-string iterable or container.
from lfp_types import is_iterable, is_container, Container
is_iterable([1, 2, 3]) # True
is_iterable("abc") # False (strings are excluded by design)
is_iterable(b"abc") # False
is_container([1, 2, 3]) # True
is_container(iter([1, 2])) # False (iterators/generators are not containers)
isinstance([1, 2, 3], Container) # True
Normalization and Flattening
Ensure you are working with an iterable or a materialized container.
from lfp_types import to_iterable, to_container
# Normalize scalars to iterables
list(to_iterable(5)) # [5]
# Pass through existing iterables
list(to_iterable([1, 2])) # [1, 2]
# Recursive flattening
list(to_iterable([1, [2, [3]]], flatten=True)) # [1, 2, 3]
# Normalize to a list/materialized container
to_container(iter([1, 2])) # [1, 2]
Boolean Parsing
Convert various representations to a boolean.
from lfp_types import to_bool
to_bool("yes") # True
to_bool("off") # False
to_bool("1") # True
to_bool(0) # False
# Custom default for unrecognized values
to_bool("maybe", default=True) # True
# Raise ValueError if default is None
to_bool("invalid", default=None) # Raises ValueError
Type Variables
Quick access to standard TypeVar names.
from lfp_types import A, B, T
def map_items(items: list[A]) -> list[B]:
...
Development
This project uses pixi for environment management and uv for builds.
pixi run pytest
Metadata
Release files for lfp-types 0.0.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| lfp_types-0.0.10.tar.gz | 6.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| lfp_types-0.0.10-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.2 kB
Release files / lfp_types-0.0.10.tar.gz
| Download URL | lfp_types-0.0.10.tar.gz |
|---|---|
| Size | 6.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
06f6440bfd88d3e8838c21c96df592ae5ff1a7feb377cb78dc6530d7ba8b1cc2
|
|
BLAKE2b-256 checksum How to use checksums |
ef8a6e58e3fcf8fe51a5d2116ad1161992a5e77fce8ff5354c123b226c8bf071
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 16, 2026.
Transparency logRelease files / lfp_types-0.0.10-py3-none-any.whl
| Download URL | lfp_types-0.0.10-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
30f594f6964136d7ea78b0bc25ba4cfedbb8667d3604cd3f916c712c5305a68c
|
|
BLAKE2b-256 checksum How to use checksums |
2b04795504274b5794f5e514b607346cee387571a969a07dd3de8c07424def10
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 16, 2026.
Transparency log