wolframclient.evaluation.cloud package¶
Submodules¶
wolframclient.evaluation.cloud.asynccloudsession module¶
-
class
wolframclient.evaluation.cloud.asynccloudsession.
WolframCloudAsyncSession
(credentials=None, server=None, loop=None, inputform_string_evaluation=True, oauth_session_class=None, xauth_session_class=None, http_sessionclass=None, ssl_context_class=None)[source]¶ Bases:
wolframclient.evaluation.base.WolframAsyncEvaluator
Interact with a Wolfram Cloud asynchronously using coroutines.
Asynchronous cloud operations are provided through coroutines using modules
asyncio
and aiohttp.Instances of this class can be managed with an asynchronous context manager:
async with WolframCloudAsyncSession() as session: await session.call(...)
An event loop can be explicitly passed using the named parameter loop; otherwise, the one returned by
get_event_loop()
is used. The initialization options of the classWolframCloudSession
are also supported by this class.-
call
(api, input_parameters={}, files={}, target_format='wl', permissions_key=None, **kwargv)[source]¶ Call a given API using the provided input parameters.
api can be a string url or a
tuple
(username, api name). The username is generally the Wolfram Language symbol$UserName
. The API name can be a UUID or a relative path, e.g. myapi/foo/bar.The input parameters are provided as a dictionary with string keys being the name of the parameters associated to their value.
Files are passed in a dictionary. Values can have multiple forms:
{'parameter name': file_pointer}
It is possible to explicitly specify a filename and a content type:
{'parameter name': ('filename', file_pointer, 'content-type')}
Bytes can also be passed as files:
{'parameter name': ('filename', b'...binary...data...', 'content-type')}
It is possible to pass a
PermissionsKey
to the server alongside the query and get access to a given resource.
-
evaluate
(expr, **kwargs)[source]¶ Send expr to the cloud for evaluation and return the result.
expr can be a Python object serializable by
export()
or the string InputForm of an expression to evaluate.
-
evaluate_wrap
(expr, **kwargs)[source]¶ Similar to
evaluate()
but return the result as aWolframEvaluationJSONResponseAsync
.
-
started
¶
-
wolframclient.evaluation.cloud.asyncoauth module¶
-
class
wolframclient.evaluation.cloud.asyncoauth.
OAuth1AIOHttpAsyncSession
(http_session, server, consumer_key, consumer_secret, signature_method=None, client_class=None, ssl_context_class=None)[source]¶ Bases:
wolframclient.evaluation.cloud.asyncoauth.OAuthAIOHttpAsyncSessionBase
OAuth1 using aiohttp.
-
class
wolframclient.evaluation.cloud.asyncoauth.
OAuthAIOHttpAsyncSessionBase
(http_session, server, consumer_key, consumer_secret, signature_method=None, client_class=None, ssl_context_class=None)[source]¶ Bases:
wolframclient.evaluation.cloud.base.OAuthAsyncSessionBase
Asynchronous OAuth authentication class using aiohttp library for requests.
-
class
wolframclient.evaluation.cloud.asyncoauth.
XAuthAIOHttpAsyncSession
(userid_password, http_session, server, signature_method=None, client_class=<class 'oauthlib.oauth1.rfc5849.Client'>)[source]¶ Bases:
wolframclient.evaluation.cloud.asyncoauth.OAuthAIOHttpAsyncSessionBase
XAuth using aiohttp.
wolframclient.evaluation.cloud.base module¶
-
class
wolframclient.evaluation.cloud.base.
SecuredAuthenticationKey
(consumer_key, consumer_secret)[source]¶ Bases:
object
Represents a Secured Authentication Key generated using the Wolfram Language function GenerateSecuredAuthenticationKey[]
It is used as an input when authenticating a cloud session.
-
is_xauth
= False¶
-
-
class
wolframclient.evaluation.cloud.base.
UserIDPassword
(user, password)[source]¶ Bases:
object
Represents user credentials used to login to a cloud.
It is used as an input when authenticating a cloud session.
-
is_xauth
= True¶
-
-
class
wolframclient.evaluation.cloud.base.
OAuthSessionBase
(server, consumer_key, consumer_secret, signature_method=None, client_class=<class 'oauthlib.oauth1.rfc5849.Client'>)[source]¶ Bases:
object
A family of classes dealing with authentication with OAuth method.
-
DEFAULT_CONTENT_TYPE
= {'Content-Type': 'application/x-www-form-urlencoded', 'User-Agent': 'WolframClientForPython/1.0'}¶
Return a reasonably accurate state of the authentication status.
-
-
class
wolframclient.evaluation.cloud.base.
OAuthAsyncSessionBase
(server, consumer_key, consumer_secret, signature_method=None, client_class=<class 'oauthlib.oauth1.rfc5849.Client'>)[source]¶
wolframclient.evaluation.cloud.cloudsession module¶
-
class
wolframclient.evaluation.cloud.cloudsession.
WolframCloudSession
(credentials=None, server=None, inputform_string_evaluation=True, oauth_session_class=None, xauth_session_class=None, http_sessionclass=None, max_workers=4)[source]¶ Bases:
wolframclient.evaluation.base.WolframEvaluator
Represent a session to a given cloud enabling simple API call.
This is the central class of the cloud evaluation package. It is initialized with a server instance representing a given cloud. By default, a session targets the Wolfram Public Cloud.
Most of the time it is necessary to authenticate with the server before issuing requests. A session supports two forms of authentication:
- 2-legged oauth using a secured authentication key
- xauth using the user ID and password
Calling an API is done through the method
call()
, which will return an instance ofWolframAPIResponse
. It is strongly advised to reuse a session to make multiple calls to mitigate the cost of initialization.max_workers can be specified and is passed to the
ThreadPoolExecutor
used for future methods.-
call
(api, input_parameters={}, files={}, target_format='wl', permissions_key=None, **kwargv)[source]¶ Call a given API using the provided input parameters.
api can be a string url or a
tuple
(username, api name). The username is generally the Wolfram Language symbol$UserName
. The API name can be a UUID or a relative path, e.g. myapi/foo/bar.The input parameters are provided as a dictionary with string keys being the name of the parameters associated to their value.
Files are passed in a dictionary. Values can have multiple forms:
{'parameter name': file_pointer}
It is possible to explicitly specify a filename and a content type:
{'parameter name': ('filename', file_pointer, 'content-type')}
String can also be passed as files:
{'parameter name': ('filename', '...string...data...', 'content-type')}
It is possible to pass a
PermissionsKey
to the server alongside the query and get access to a given resource.
-
call_future
(api, input_parameters={}, target_format='wl', permissions_key=None, **kwargv)[source]¶ Call a given API asynchronously and return a
Future
object.See
WolframCloudSession.call()
for more details about input parameters.
-
evaluate
(expr, **kwargs)[source]¶ Send expr to the cloud for evaluation and return the result.
expr can be a Python object serializable by
export()
or the string InputForm of an expression to evaluate.
-
evaluate_future
(expr, **kwargs)[source]¶ Send expr to the cloud for asynchronous evaluation and return a
Future
object.expr can be a Python object serializable by
export()
or the string InputForm of an expression to evaluate.
-
evaluate_wrap
(expr, **kwargs)[source]¶ Similar to
evaluate()
but return the result as aWolframCloudEvaluationResponse
.
-
evaluate_wrap_future
(expr, **kwargs)[source]¶ Asynchronously call evaluate_wrap.
Return a
Future
object.
-
pool
¶
-
start
()[source]¶ Start the evaluator.
Once this function is called, the evaluator must be ready to evaluate incoming expressions.
-
started
¶
-
stop
()[source]¶ Gracefully stop the evaluator. Try to stop the evaluator but wait for the current evaluation to finish first.
wolframclient.evaluation.cloud.oauth module¶
-
class
wolframclient.evaluation.cloud.oauth.
OAuth1RequestsSyncSession
(http_session, server, consumer_key, consumer_secret, signature_method=None, client_class=None)[source]¶ Bases:
wolframclient.evaluation.cloud.oauth.OAuthRequestsSyncSessionBase
Oauth1 authentication using secured authentication key, as expected by the requests library.
-
class
wolframclient.evaluation.cloud.oauth.
XAuthRequestsSyncSession
(userid_password, http_session, server, consumer_key, consumer_secret, signature_method=None, client_class=<class 'oauthlib.oauth1.rfc5849.Client'>)[source]¶ Bases:
wolframclient.evaluation.cloud.oauth.OAuthRequestsSyncSessionBase
XAuth authentication as expected by the requests library.
xauth authenticates with user and password, but requires a specific server configuration.
wolframclient.evaluation.cloud.request_adapter module¶
wolframclient.evaluation.cloud.server module¶
-
class
wolframclient.evaluation.cloud.server.
WolframServer
(cloudbase, request_token_endpoint, access_token_endpoint, xauth_consumer_key=None, xauth_consumer_secret=None, certificate=None)[source]¶ Bases:
object
Represents the cloud server.
Contains the authentication endpoints information, the API endpoint aka. the cloud base ($CloudBase in the Wolfram Language), and eventually the xauth consumer key and secret.
Module contents¶
-
class
wolframclient.evaluation.cloud.
WolframServer
(cloudbase, request_token_endpoint, access_token_endpoint, xauth_consumer_key=None, xauth_consumer_secret=None, certificate=None)[source]¶ Bases:
object
Represents the cloud server.
Contains the authentication endpoints information, the API endpoint aka. the cloud base ($CloudBase in the Wolfram Language), and eventually the xauth consumer key and secret.
-
class
wolframclient.evaluation.cloud.
WolframCloudSession
(credentials=None, server=None, inputform_string_evaluation=True, oauth_session_class=None, xauth_session_class=None, http_sessionclass=None, max_workers=4)[source]¶ Bases:
wolframclient.evaluation.base.WolframEvaluator
Represent a session to a given cloud enabling simple API call.
This is the central class of the cloud evaluation package. It is initialized with a server instance representing a given cloud. By default, a session targets the Wolfram Public Cloud.
Most of the time it is necessary to authenticate with the server before issuing requests. A session supports two forms of authentication:
- 2-legged oauth using a secured authentication key
- xauth using the user ID and password
Calling an API is done through the method
call()
, which will return an instance ofWolframAPIResponse
. It is strongly advised to reuse a session to make multiple calls to mitigate the cost of initialization.max_workers can be specified and is passed to the
ThreadPoolExecutor
used for future methods.-
call
(api, input_parameters={}, files={}, target_format='wl', permissions_key=None, **kwargv)[source]¶ Call a given API using the provided input parameters.
api can be a string url or a
tuple
(username, api name). The username is generally the Wolfram Language symbol$UserName
. The API name can be a UUID or a relative path, e.g. myapi/foo/bar.The input parameters are provided as a dictionary with string keys being the name of the parameters associated to their value.
Files are passed in a dictionary. Values can have multiple forms:
{'parameter name': file_pointer}
It is possible to explicitly specify a filename and a content type:
{'parameter name': ('filename', file_pointer, 'content-type')}
String can also be passed as files:
{'parameter name': ('filename', '...string...data...', 'content-type')}
It is possible to pass a
PermissionsKey
to the server alongside the query and get access to a given resource.
-
call_future
(api, input_parameters={}, target_format='wl', permissions_key=None, **kwargv)[source]¶ Call a given API asynchronously and return a
Future
object.See
WolframCloudSession.call()
for more details about input parameters.
-
evaluate
(expr, **kwargs)[source]¶ Send expr to the cloud for evaluation and return the result.
expr can be a Python object serializable by
export()
or the string InputForm of an expression to evaluate.
-
evaluate_future
(expr, **kwargs)[source]¶ Send expr to the cloud for asynchronous evaluation and return a
Future
object.expr can be a Python object serializable by
export()
or the string InputForm of an expression to evaluate.
-
evaluate_wrap
(expr, **kwargs)[source]¶ Similar to
evaluate()
but return the result as aWolframCloudEvaluationResponse
.
-
evaluate_wrap_future
(expr, **kwargs)[source]¶ Asynchronously call evaluate_wrap.
Return a
Future
object.
-
pool
¶
-
start
()[source]¶ Start the evaluator.
Once this function is called, the evaluator must be ready to evaluate incoming expressions.
-
started
¶
-
stop
()[source]¶ Gracefully stop the evaluator. Try to stop the evaluator but wait for the current evaluation to finish first.
-
class
wolframclient.evaluation.cloud.
WolframAPICall
(target, api, permission_key=None)[source]¶ Bases:
wolframclient.evaluation.cloud.base.WolframAPICallBase
Helper class to perform an API call using a cloud session.
-
class
wolframclient.evaluation.cloud.
SecuredAuthenticationKey
(consumer_key, consumer_secret)[source]¶ Bases:
object
Represents a Secured Authentication Key generated using the Wolfram Language function GenerateSecuredAuthenticationKey[]
It is used as an input when authenticating a cloud session.
-
is_xauth
= False¶
-
-
class
wolframclient.evaluation.cloud.
UserIDPassword
(user, password)[source]¶ Bases:
object
Represents user credentials used to login to a cloud.
It is used as an input when authenticating a cloud session.
-
is_xauth
= True¶
-
-
class
wolframclient.evaluation.cloud.
WolframAPICallAsync
(target, api, permission_key=None)[source]¶ Bases:
wolframclient.evaluation.cloud.base.WolframAPICallBase
Perform an API call using an asynchronous cloud session.
-
class
wolframclient.evaluation.cloud.
WolframCloudAsyncSession
(credentials=None, server=None, loop=None, inputform_string_evaluation=True, oauth_session_class=None, xauth_session_class=None, http_sessionclass=None, ssl_context_class=None)[source]¶ Bases:
wolframclient.evaluation.base.WolframAsyncEvaluator
Interact with a Wolfram Cloud asynchronously using coroutines.
Asynchronous cloud operations are provided through coroutines using modules
asyncio
and aiohttp.Instances of this class can be managed with an asynchronous context manager:
async with WolframCloudAsyncSession() as session: await session.call(...)
An event loop can be explicitly passed using the named parameter loop; otherwise, the one returned by
get_event_loop()
is used. The initialization options of the classWolframCloudSession
are also supported by this class.-
call
(api, input_parameters={}, files={}, target_format='wl', permissions_key=None, **kwargv)[source]¶ Call a given API using the provided input parameters.
api can be a string url or a
tuple
(username, api name). The username is generally the Wolfram Language symbol$UserName
. The API name can be a UUID or a relative path, e.g. myapi/foo/bar.The input parameters are provided as a dictionary with string keys being the name of the parameters associated to their value.
Files are passed in a dictionary. Values can have multiple forms:
{'parameter name': file_pointer}
It is possible to explicitly specify a filename and a content type:
{'parameter name': ('filename', file_pointer, 'content-type')}
Bytes can also be passed as files:
{'parameter name': ('filename', b'...binary...data...', 'content-type')}
It is possible to pass a
PermissionsKey
to the server alongside the query and get access to a given resource.
-
evaluate
(expr, **kwargs)[source]¶ Send expr to the cloud for evaluation and return the result.
expr can be a Python object serializable by
export()
or the string InputForm of an expression to evaluate.
-
evaluate_wrap
(expr, **kwargs)[source]¶ Similar to
evaluate()
but return the result as aWolframEvaluationJSONResponseAsync
.
-
started
¶
-