Remote Python Execution Functionality
Functionality for the generation and management of remote Python function execution.
Warning
This functionality is provided in it's present form as a BETA
Feature and is subject to change. To enable this functionality
for testing please following configuration instructions
here setting PYKX_BETA_FEATURES='true'
session
session()
A session refers to a connection to a remote kdb+/q process against which users are defining/registering Python Functions which will return results to a Python session.
add_library
add_library(*args)
Add a list of Python libraries which will be imported prior to definition of a remote Python function, this allows users for example to import numpy and use it as a defined library within a remote function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
A list of strings denoting the packages which are to be imported for use by a remote function. |
()
|
Returns:
Type | Description |
---|---|
Returns a |
>>> from pykx.remote import session
>>> remote_session = session()
>>> remote_session.add_library('numpy', 'pandas')
create
create(
host="localhost",
port=None,
*,
username="",
password="",
timeout=0.0,
large_messages=True,
tls=False
)
Populate a session for use when generating a function for remote execution. This
session will be backed by a SyncQConnection instance, note that only one session
can be associated with a given instance of a session
class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
host |
Union[str, bytes]
|
The host name to which a connection is to be established. |
'localhost'
|
port |
int
|
The port to which a connection is to be established. |
None
|
username |
Union[str, bytes]
|
Username for q connection authorization. |
''
|
password |
Union[str, bytes]
|
Password for q connection authorization. |
''
|
timeout |
float
|
Timeout for blocking socket operations in seconds. If set to |
0.0
|
large_messages |
bool
|
Whether support for messages >2GB should be enabled. |
True
|
tls |
bool
|
Whether TLS should be used. |
False
|
Returns:
Type | Description |
---|---|
Returns a |
-
Connect to a q session on localhost at port 5050
>>> from pykx.remote import session >>> remote_session = session() >>> remote_session.create(port = 5050)
-
Connect to a user-password protected q session at a defined port
>>> from pykx.remote import session >>> remote_session = session() >>> remote_session.create_session(port=5001, username='username', password='password')
clear
clear()
Reset/clear the session and libraries associated with a defined session information
Example:
>>> from pykx.remote import session
>>> remote_session = session()
>>> remote_session.create(port = 5050)
>>> remote_session.add_library('numpy')
>>> {'session': session._session, 'libraries': session._libraries}
{'session': pykx.QConnection(port=5001), 'libraries': ['numpy']}
>>> remote_session.clear()
>>> {'session': session._session, 'libraries': session._libraries}
{'session': None, 'libraries': []}
function
function(remote_session, *args)
This decorator allows users to tag functions which will be executed
on a remote server defined by a kx.remote.session
instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
remote_session |
Valid |
required | |
*args |
When invoked the decorated function will be passed supplied arguments |
()
|
Returns:
Type | Description |
---|---|
When invoked the decorated function will return the result as a PyKX object to the |
|
calling process |
Examples:
-
Call a basic decorated function on a remote process
>>> from pykx.remote import session, function >>> remote_session = session() >>> session.create(port = 5050) >>> @function(session) ... def func(x): ... return x+1 >>> func(1) pykx.LongAtom(pykx.q('2'))
-
Apply a function making use of a named library
>>> from pykx.remote import session, function >>> remote_session = session() >>> session.create(port = 5050) >>> session.add_library('numpy') >>> @function(session) ... def func(start, stop, count): ... return numpy.linspace(start, stop, count) >>> func(0, 10, 5) pykx.FloatVector(pykx.q('0 2.5 5 7.5 10'))