Skip to main content

A module for dynamically calling Python functions

Project description

Qcall

Qcall is a module for dynamically calling Python functions.

Qcall stands for "quick call".

Here is a simple example:

>>> from qcall import call
>>> call("print", "hello", "world")
hello world

The above code is equivalent to the following:

>>> print("hello", "world")
hello world

Using Qcall you can invoke any Python function, constructor or method. Qcall performs automatic module import, parameter rearrangement if needed, and returns the result of the function call.

Qcall is useful for implementing domain-specific languages, processing configuration files, and more.

Installation

Install default version from the Python Package Index:

pip install qcall

Examples

from qcall import call, QCALL_CONTEXT


y_true = [1.0, 0.0]
y_score = [0.8, 0.2]

# no need to import sklearn.metrics
# let's dynamically call the roc_auc_score function:
result = call("sklearn.metrics.roc_auc_score", y_true, y_score)


# the same result using **kwargs:
result = call(
    "sklearn.metrics.roc_auc_score",
    y_score=y_score,
    y_true=y_true
)

result = call(
    "sklearn.metrics.roc_auc_score",
    **{"y_score": y_score, "y_true": y_true}
)

# Positional argument(s) can be passed through **kwards using the '*' key.
# For example, this is useful when the arguments are specified in a YAML file.

result = call(
    "sklearn.metrics.roc_auc_score",
    **{"*": [y_true, y_score]}
)

# IMPORTANT: if the function to be call has only one postional argument,
# and the '*' key contains only a list argument,
# it should be wrapped with another list for correct function call:
def some_function(a):
    print(a)

result = call("some_function", **{'*': [[1, 2, 3]], QCALL_CONTEXT: locals()})
# the above is equalent to: some_function([1, 2, 3])

# an example of calling a built-in function:
max_value = call("max", [1, 3, 5, 7])

# an example of calling a constructor:
classifier = call("sklearn.linear_model.LogisticRegression")

x_train = [[0.0], [1.0]]
y_train = [0.0, 1.0]

# examples of calling methods and using the context parameter:
call("classifier.fit", x_train, y_train, qcall_context=locals())
x_test = [[0.1], [0.9]]
p_test = call("classifier.predict_proba", x_test, qcall_context=locals())

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

qcall-0.1.2.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

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

qcall-0.1.2-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file qcall-0.1.2.tar.gz.

File metadata

  • Download URL: qcall-0.1.2.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.0

File hashes

Hashes for qcall-0.1.2.tar.gz
Algorithm Hash digest
SHA256 46e87cc8ec62542f65424f374f008fbd6f8004cd2de99d75bc0cf5e7c2a3121b
MD5 e5bcb1bfacbcb5823f4930ad7ab4d9b7
BLAKE2b-256 52b97b7fee7bd001a54a2556a85b7542fbf4670fc7e8db63ec4831a2eb79269e

See more details on using hashes here.

File details

Details for the file qcall-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: qcall-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.0

File hashes

Hashes for qcall-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5bce85ecd76e8f551fadec95def6027527d73bf241b75127d55b262ad6493d8a
MD5 faf28e89eedfe4d0f97c703a8cbb1ac1
BLAKE2b-256 82a58abf00a6547255213bbc89f1c92a76b2e20e0d87ddc46d28f5483ac243f6

See more details on using hashes here.

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