Skip to main content

combu

build python license coverage

Execute your method with combination parameters.

Use cases

  • Testing
    • Test pattern.
  • Machine learning
    • Model validation.
    • Grid search.
  • Web Scraping
    • Query parameters pattern.

Install

pip install combu

Usage

One time loop

import combu

def func(v1, v2):
   return v1 + v2


params = {'v1': ['a', 'b'], 'v2': ['A', 'B']}
for res, param in combu.execute(func, params):
   print(res, param)

# Output
'''
aA {'v1': 'a', 'v2': 'A'}
aB {'v1': 'a', 'v2': 'B'}
bA {'v1': 'b', 'v2': 'A'}
bB {'v1': 'b', 'v2': 'B'}
'''

# Set loop order
order = ['v2', 'v1']
for res, param in combu.execute(func, params, order=order):
   print(res, param)

# Output
'''
aA {'v2': 'A', 'v1': 'a'}
bA {'v2': 'A', 'v1': 'b'}
aB {'v2': 'B', 'v1': 'a'}
bB {'v2': 'B', 'v1': 'b'}
'''

Reloopable by using class

import combu

def func(v1, v2):
   return v1 + v2

comb = combu.Combu(func)
# You can set order on initializer.
# comb = combu.Combu(func, order=['v2', 'v1'])
# If you want to show progress bar.
# comb = combu.Combu(func, progress=True)

params = {'v1': ['a', 'b'], 'v2': ['A', 'B']}
for res, param in comb.execute(params):
   print(res, param)

params = {'v1': ['x', 'y'], 'v2': ['X', 'Y']}
for res, param in comb.execute(params):
   print(res, param)

# You can set order on Combu.execute().
for res, param in comb.execute(params, order=['v2', 'v1']):
   print(res, param)

Hooks

  • Hooks flow

    order = [A, B]
    
    before_a()
    for a in A:
       before_b()
       before_each_a()
       for b in B:
          before_each_b()
          func()
          after_each_b()
       after_each_a()
       after_b()
    after_a()
    
  • Define hooks.

    def func(v1, v2):
       pass
    
    def before_v1(v1, v2):
       pass
    
    # Initialize with hooks.
    # Available:
    # * before
    # * after
    # * before_each
    # * after_each
    comb = Comb(func, before={'v1': before_v1})
    
    # Set a hook after initialized.
    # Available:
    # * set_before(k, func)
    # * set_after(k, func)
    # * set_before_each(k, func)
    # * set_after_each(k, func)
    comb.set_before('v1', before_v1)
    

Parallel

# Use n_jobs parameter.
for res, param in combu.execute(func, params, n_jobs=2):
   print(res, param)


# Use combu.CombuParallel and n_jobs.
# n_jobs=-1 mean "use all cores."
comb = combu.CombuParallel(func, n_jobs=-1)

Utility

  • Create parameter combination (not execute any functions).
    • combu.create_values
  • Count combinations.
    • combu.util.count
  • Shuffle parameters.
    • combu.util.shuffle_params

Aliases

  • combu.exec -> combu.execute
  • combu.values -> combu.create_values

Examples

  • Available on ./examples.

Development

  • Requirements: poetry, pyenv
# Setup
poetry install

# Lint & Test
mkdir report
poetry run flake8 --format=html --htmldir=report/flake-report src/ tests/
poetry run mypy src/ tests/combu/
poetry run pytest tests/
poetry run pytest tests/ --cov-report html:report/coverage

# Build and publish
poetry run python create_badges.py
poetry build
poetry publish

Release files for combu 1.2.1

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

Source distribution (sdist)

Source distribution for combu 1.2.1
File Size Uploaded
combu-1.2.1.tar.gz 8.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for combu 1.2.1
File Interpreter ABI Platform
combu-1.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 17.4 kB

Release files / combu-1.2.1.tar.gz

Download URL combu-1.2.1.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
f312fbf8ee704f644e8098522e4c1cd938356189c11fd9fd84406bfa987f10d8
BLAKE2b-256 checksum
How to use checksums
210f7f526b664f37dbe34f103dce9f3cdaac8886c79e7df447e0ae261d425a0e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.6.12 Linux/4.19.128-microsoft-standard

Release files / combu-1.2.1-py3-none-any.whl

Download URL combu-1.2.1-py3-none-any.whl
Size 8.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
efb3ce33e48791c1d0622e47eacf25a12273853071b39d54ac39ae8df44cc473
BLAKE2b-256 checksum
How to use checksums
ba29456fbb03ef3c2ce994f4464a21577f935800f9e15f981316594bb4c90f55
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.6.12 Linux/4.19.128-microsoft-standard

Release history Release notifications | RSS feed

This release

1.2.1 This release

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

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