Skip to main content

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, and is_sequence helper checks.
  • Normalization: to_iterable and to_container helpers to handle scalars and collections uniformly.
  • Flattening: Optional recursive flattening for nested iterables.
  • Boolean Parsing: to_bool parser with support for common truthy and falsy string/numeric values.
  • Type Variables: Public TypeVar exports for A through Z.

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

lfp_types-0.0.9.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lfp_types-0.0.9-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file lfp_types-0.0.9.tar.gz.

File metadata

  • Download URL: lfp_types-0.0.9.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for lfp_types-0.0.9.tar.gz
Algorithm Hash digest
SHA256 7fd9dae9a1a49d96bcc3f51be7dd19c7ae5e03dc14eef1a183d5d27723926e72
MD5 8723050b8120b312508dcebb87f732dc
BLAKE2b-256 6b38ce4aeae902dec9a65146ca6d88c1e22e8209c022a87f981969a639e1f902

See more details on using hashes here.

Provenance

The following attestation bundles were made for lfp_types-0.0.9.tar.gz:

Publisher: publish.yml on regbo/lfp-types-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lfp_types-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: lfp_types-0.0.9-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

Hashes for lfp_types-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 2beb57fe79fd96dea03be33d294fa522d7ac36f0c0dc521462152ea2de4fe489
MD5 1c1f4efe8f7d5c5688ed90f0988315d1
BLAKE2b-256 7212fe917fe3d1ace852ffa277ee40d4ea0ce6dd480899348d41c26e5efb40fe

See more details on using hashes here.

Provenance

The following attestation bundles were made for lfp_types-0.0.9-py3-none-any.whl:

Publisher: publish.yml on regbo/lfp-types-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page