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.1.tar.gz (8.1 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.1-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: qcall-0.1.1.tar.gz
  • Upload date:
  • Size: 8.1 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.1.tar.gz
Algorithm Hash digest
SHA256 f18e0fb7d302c160cbf9dbdf4b9f309393deb1cda1f0ae6702c73448aa5ec4d9
MD5 f800b74bf3bcd520568b5d71a4554fad
BLAKE2b-256 5fddc5d3ff322379ded8f61e2e8ba746dbdfc38f18a9e6b9a5c60f435abad061

See more details on using hashes here.

File details

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

File metadata

  • Download URL: qcall-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.6 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7d574bac0658dc305ed1f7b077f904368709ea3de02649b98df4e3019552d762
MD5 9171fb76bc15c110bcf3caa96af6f4ec
BLAKE2b-256 dd92ad83ab7f52d5a291586076f1f6cbb0466312b76e848296eb3245027951bb

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