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.10.tar.gz (6.0 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.10-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

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

Hashes for lfp_types-0.0.10.tar.gz
Algorithm Hash digest
SHA256 06f6440bfd88d3e8838c21c96df592ae5ff1a7feb377cb78dc6530d7ba8b1cc2
MD5 f1f7781b3a0e07b033cd741fb62f1f78
BLAKE2b-256 ef8a6e58e3fcf8fe51a5d2116ad1161992a5e77fce8ff5354c123b226c8bf071

See more details on using hashes here.

Provenance

The following attestation bundles were made for lfp_types-0.0.10.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.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

Hashes for lfp_types-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 30f594f6964136d7ea78b0bc25ba4cfedbb8667d3604cd3f916c712c5305a68c
MD5 5c0a01676a75c1b07ba974fe5af70402
BLAKE2b-256 2b04795504274b5794f5e514b607346cee387571a969a07dd3de8c07424def10

See more details on using hashes here.

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

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