Skip to main content

Type stubs for toolz

Project description

toolz-stubs

CI basedpyright pyright

Type stubs for toolz and tlz - Python functional programming libraries.

Installation

pip install toolz-stubs

This installs type stubs for both toolz and tlz.

Usage

Once installed, type checkers like mypy, pyright, or basedpyright will automatically use these stubs:

import toolz

bills = {"Alice": [20, 15, 30], "Bob": [10, 35]}
totals = toolz.valmap(sum, bills)  # dict[str, int]

even_entries = toolz.keyfilter(lambda k: k % 2 == 0, {1: "a", 2: "b", 3: "c"})  # dict[int, str]

names = ["Alice", "Bob", "Charlie", "Anna"]
grouped = toolz.groupby(lambda s: s[0], names)  # dict[str, list[str]]

Using with cytoolz

When you pip install toolz, you also get a second package called tlz. It's a thin auto-selecting wrapper: if cytoolz (the C-accelerated version) is installed, tlz imports from it; otherwise it falls back to pure-Python toolz. The API is identical either way.

If you use cytoolz, you can switch your imports to tlz to get the same performance with type checking support and a graceful fallback:

# before
from cytoolz.dicttoolz import merge, valmap
from cytoolz.functoolz import curry, compose, pipe

# after — same performance, now with type stubs
from tlz.dicttoolz import merge, valmap
from tlz.functoolz import curry, compose, pipe

What's Included

This package provides type stubs (.pyi files) for:

  • toolz: The pure Python functional programming library
  • tlz: The auto-selecting wrapper (uses cytoolz if installed, otherwise falls back to toolz)

Modules covered:

  • toolz.functoolz / tlz.functoolz - Function manipulation (curry, compose, pipe, etc.)
  • toolz.itertoolz / tlz.itertoolz - Iterator utilities (groupby, partition, sliding_window, etc.)
  • toolz.dicttoolz / tlz.dicttoolz - Dictionary operations (merge, valmap, keyfilter, etc.)
  • toolz.curried / tlz.curried - Pre-curried versions of all functions
  • toolz.recipes / tlz.recipes - Common recipes (countby, partitionby)
  • toolz.sandbox / tlz.sandbox - Experimental utilities

Development

make sync    # Install dependencies
make check   # Run type checker
make test    # Run tests
make lint    # Run linter
make format  # Check formatting
make build   # Build wheel

If manually running commands, be sure to specify --no-editable or hatchling will mispackage toolz & tlz packages.

Tests

The tests in tests/ serve a few purposes:

  • they verify runtime behavior with pytest.
  • they verify that these stubs genuinely improve the developer experience in an IDE.
  • they are type-checked by basedpyright. This ensures the stubs match actual library behavior.

Contributing

Contributions are welcome! Areas that could use improvement:

  1. More precise generic types
  2. Additional overloads for functions with variable signatures
  3. Improved curry and composition typing
  4. Protocol types for duck-typed parameters

License

BSD 3-Clause (same as toolz)

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

toolz_stubs-0.4.0.tar.gz (64.8 kB view details)

Uploaded Source

Built Distribution

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

toolz_stubs-0.4.0-py3-none-any.whl (68.1 kB view details)

Uploaded Python 3

File details

Details for the file toolz_stubs-0.4.0.tar.gz.

File metadata

  • Download URL: toolz_stubs-0.4.0.tar.gz
  • Upload date:
  • Size: 64.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for toolz_stubs-0.4.0.tar.gz
Algorithm Hash digest
SHA256 d32a2054cd299905232400bcde934e9012538eff3455c7b13b04befbf4aa73ac
MD5 0e2cedeb30b04fe41f800e0ec8951be7
BLAKE2b-256 43fd2c97773a69f6ccca3be1f843ce2151ed9fe4ee9989bb0e9b01b226b83871

See more details on using hashes here.

Provenance

The following attestation bundles were made for toolz_stubs-0.4.0.tar.gz:

Publisher: publish.yml on mgrinshpon/toolz-stubs

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

File details

Details for the file toolz_stubs-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: toolz_stubs-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 68.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for toolz_stubs-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4eaa97b55a981de6af44b2739c17cc4a102fac32a0284789d77c36b4fa6c6c44
MD5 764e38a4a9c56cb1da2442fdd43590ec
BLAKE2b-256 764fc27310714b65079b64b6e1667c7cb7689bfedb54e436b54e2c6f79b0ef6d

See more details on using hashes here.

Provenance

The following attestation bundles were made for toolz_stubs-0.4.0-py3-none-any.whl:

Publisher: publish.yml on mgrinshpon/toolz-stubs

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