Skip to main content

Python partial on steroids

https://travis-ci.org/5monkeys/partialize.png?branch=master

Like python functools.partial but with change/extend access to args and kwargs. Also a great tool even if no partial is needed but the function takes args/kwargs that often depends on logic.

Easiest used as a decorator

from partialize import partialize

@partialize
def dummy(a, b, c=None):
    return 'hello world'

partial_dummy = dummy.partial(1)
partial_dummy.b = 2
partial_dummy(c=3)

or invoked inline…

partial_dummy = partialize(dummy)
partial_dummy.a = 1
partial_dummy.update(b=2)
partial_dummy()
partial_dummy(c=3)

Use it on functions that needs logic to affect arguments passed, instead of building and passing a dict as kwargs which often gets quite messy and hard to read.

Dict kwargs example:

from partialize import partialize

@partialize
def search_products(site, query=None, brand=None, tags=None):
    pass

kwargs = {}

if logic:
    kwargs['query'] = q

if more_logic:
    kwargs['brand'] = 'brand name'

products = search_products(site, **kwargs)

Partialize example:

search = search_products.partial(site)

if logic:
    search.query = q

if more_logic:
    search.brand = 'brand name'

products = search()

Note: function argument names are validated when set, unlike dict string keys.

Metadata

Release files for partialize 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for partialize 0.0.3
File Size Uploaded Provenance Actions
partialize-0.0.3.tar.gz 4.7 kB Without provenance Details for partialize-0.0.3.tar.gz

Release files / partialize-0.0.3.tar.gz

Download URL partialize-0.0.3.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
54a9038139987c7d073f6f929225c8ab533590cbeba77df7a3b0f629e03915bc
BLAKE2b-256 checksum
How to use checksums
26112352f88f9c17f3d49a6132afa1fadc2d7e1ea4c441ab0d7d642e26a5adee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for partialize 0.0.3

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.3 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page