Lightweight runtime typing helpers for iterable and container normalization.
Project description
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
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lfp_types-0.0.10.tar.gz.
File metadata
- Download URL: lfp_types-0.0.10.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06f6440bfd88d3e8838c21c96df592ae5ff1a7feb377cb78dc6530d7ba8b1cc2
|
|
| MD5 |
f1f7781b3a0e07b033cd741fb62f1f78
|
|
| BLAKE2b-256 |
ef8a6e58e3fcf8fe51a5d2116ad1161992a5e77fce8ff5354c123b226c8bf071
|
Provenance
The following attestation bundles were made for lfp_types-0.0.10.tar.gz:
Publisher:
publish.yml on regbo/lfp-types-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lfp_types-0.0.10.tar.gz -
Subject digest:
06f6440bfd88d3e8838c21c96df592ae5ff1a7feb377cb78dc6530d7ba8b1cc2 - Sigstore transparency entry: 1321803613
- Sigstore integration time:
-
Permalink:
regbo/lfp-types-py@a95a8b21388fd204c2a3018771b2061bbf392b64 -
Branch / Tag:
refs/tags/v0.0.10 - Owner: https://github.com/regbo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a95a8b21388fd204c2a3018771b2061bbf392b64 -
Trigger Event:
push
-
Statement type:
File details
Details for the file lfp_types-0.0.10-py3-none-any.whl.
File metadata
- Download URL: lfp_types-0.0.10-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30f594f6964136d7ea78b0bc25ba4cfedbb8667d3604cd3f916c712c5305a68c
|
|
| MD5 |
5c0a01676a75c1b07ba974fe5af70402
|
|
| BLAKE2b-256 |
2b04795504274b5794f5e514b607346cee387571a969a07dd3de8c07424def10
|
Provenance
The following attestation bundles were made for lfp_types-0.0.10-py3-none-any.whl:
Publisher:
publish.yml on regbo/lfp-types-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lfp_types-0.0.10-py3-none-any.whl -
Subject digest:
30f594f6964136d7ea78b0bc25ba4cfedbb8667d3604cd3f916c712c5305a68c - Sigstore transparency entry: 1321803696
- Sigstore integration time:
-
Permalink:
regbo/lfp-types-py@a95a8b21388fd204c2a3018771b2061bbf392b64 -
Branch / Tag:
refs/tags/v0.0.10 - Owner: https://github.com/regbo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a95a8b21388fd204c2a3018771b2061bbf392b64 -
Trigger Event:
push
-
Statement type: