Pyxa Environment

Pyxa is a special subset of Python which is highly optimized for security and privacy. The syntax of the language is not modified from Python2.7. But, the runtime semantics is slightly different.

Runtime Environment

Built-in Data Structures

dict, set, list, tuple are all supported.

Global Reference

In order to use global references, you have to define your variable like this:

a = "my value"
global a
@taxa.route("/my_url")
def myFunc():
    response.add(a)

Global references have to be explicitly declared. You can also do this:

a = "my value"
@taxa.route("/my_url")
def myFunc():
    global a
    response.add(a)

Import

Dynamic imports are not supported since the tService only supports single file mode in the devnet. Besides that, the developer can only import the supported libraries mentioned below.

Warning: Importing an unsupported module will cause the a run-time error.

Return Size

In the devnet, each tService request and response cannot contain more than 8KB of data in the "data" section. For example:

@taxa.route("/my_url")
def myFunc():
    response.add("8KB OF DATA")

Helper Functions

global h
def h():
    return h2()

global h2
def h2():
    return "h2 called"    

@taxa.route("/")
def f():
    response.add(h())

Helper functions also need to obey the global reference rules.

Generator and For Loops

global gen
def gen():
    yield 1
    yield 2
    for x in xrange(3):
        yield x

@taxa.route("/f")
def f():
    response.add(str(list(gen())))  # [1, 2, 0, 1, 2]

Supported Libraries

On the Devnet, Pyxa supports a subset of standard Python libraries and several additional libraries.

import math         # https://docs.python.org/2/library/math.html
import cmath        # https://docs.python.org/2/library/cmath.html
import collections  # same as collections, https://docs.python.org/2/library/collections.html
import itertools    # https://docs.python.org/2.7/library/itertools.html
import array        # https://docs.python.org/2/library/array.html
import binascii     # https://docs.python.org/2/library/binascii.html, base64 encode/decode included
import json         # Derived from pypyjson, code releasing soon
import md5          # https://docs.python.org/2/library/md5.html
import pyaes        # https://github.com/ricmoo/pyaes
import sha          # https://docs.python.org/2/library/sha.html
import sha256       # https://github.com/delqn/py-sha256/blob/master/sha256.py
import sha3         # https://pypi.org/project/pysha3/