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 are 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 tServices only support 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 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")
Logging
There is a function taxa.log()
that can be used to create a log file within
the tservice.
taxa.add_owner("TXTe88d049854aaf163650bcc7133dc6781") @taxa.route("/test") def test(): taxa.log("start") crash() taxa.log("after")
To access the log file, in the response there will be a field called log
that
will contain the contents of the log file.
The log will only show up for requests made by one of the "owners". Non-owners
will always get a blank log. At the top of the tservice make a call to
taxa.add_owner()
, and pass in a userID. To get a userID, make the following call
on the command line:
python3 -mtaxa_sdk.get_userid path/to/keyfile.json
This command will return the userID for a keyfile that's passed in. A userID is basically just the sha256 hash of the public key, truncated to 16 bytes and then hex encoded, and then prepended with "TXT".
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.
Built-in Types
int()
- Integerunicode()
- Unicode stringstr()
- Non-Unicode stringdict()
- Dictionarylong()
- Long Integerset()
- Collections with automatically removed duplicateslist()
- General collections. Unlike tuple, these collections can be extended after initializing. Individual items can also be changed.bytearray()
- Return a new array of bytesfloat()
- An integer with a decimal parttuple()
- A list that can't have its size changed after initialization. Often used as an optimized list.bool()
- Evaluates input to eitherTrue
orFalse
Built-in Functions
abs()
- Absolute value
>>> abs(-3) 3 <<< abs(3) 3
divmod()
- division with remainder
>>> divmod(7, 2) (3, 1)
input()
- Not implementedopen()
- Not implementedstaticmethod()
- Turns a class method from an instance method into a method on the class itself. Usually used as a decorator. The method does not need the "self" argument.
class Test(object): def instance_method(self): return 'i' @staticmethod def static(): return 's' >>> t = Test() >>> t.instance_method() 'i' >>> t.static() 's' >>> Test.static() 's' >>> Test.instance_method() TypeError: instance_method() missing 1 required positional argument: 'self'
all()
- Returns True if all the items passed in collection evaluate to True.
>>> all([1, 1, 1, 1, 1, 1]) True >>> all([1, 1, 1, 0, 1, 1]) False
enumerate()
- Adds a ordinal to each item in an iterable. Most commonly used when iterating through a collection and you want to keep count while doing so.
>>> enumerate(['a', 'b', 'c']) [(0, 'a'), (1, 'b'), (2, 'c')]
ord()
- The reverse ofchr()
. Returns an integer corresponding to the passed in character.
any()
- Similar toall()
, except it returns True if any item evaluates to True.eval()
- Not Implementedisinstance()
- Returns True if the first argument is an instance of the second argument (which should always be a class).
>>> isinstance(4, int) True
pow()
- Raise first argument to the power of the second argument
>>> pow(3, 2) 9
sum()
- Adds up all numbers in the collection passed in
>>> sum([1, 2, 3, 4, 5]) 15
basestring()
- This abstract type is the superclass forstr
andunicode
. It cannot be called or instantiated, but it can be used to test whether an object is an instance ofstr
orunicode
.isinstance(obj, basestring)
is equivalent toisinstance(obj, (str, unicode))
.execfile()
- Not implementedissubclass()
- Return True if class is a subclass (direct, indirect or virtual) of classinfo. A class is considered a subclass of itself. classinfo may be a tuple of class objects, in which case every entry in classinfo will be checked. In any other case, aTypeError
exception is raised.print()
- Not implementedsuper()
- Calls to the superclass implementationbin()
- Returns a string of the binary representation of the passed in integer. The result always starts with "0b".
>>> bin(97656) '0b10111110101111000'
file()
- Constructor function for thefile
type. The constructor’s arguments are the same as those of theopen()
built-in function.iter()
- Return an iterator objectproperty()
- Return a property attribute for new-style classes (classes that derive fromobject
)filter()
- Construct a list from those elements of iterable for which function returns Truelen()
- Returns the length of the passed-in collection
>>> len([1,2,3,4]) 4
range()
- Generates a list of integers
>>> range(2, 8) [2, 3, 4, 5, 6, 7] >>> range(2, 8, 2) [2, 4, 6]
type()
- Returns the type of the passed-in object
>>> type(3) is int True
raw_input()
- Not implementedunichr()
- Return the Unicode string of one character whose Unicode code is the integer i.callable()
- ReturnTrue
if the object argument appears callable,False
if not.format()
- Convert a value to a “formatted” representation, as controlled by format_spec.locals()
- Update and return a dictionary representing the current local symbol table.reduce()
- Apply function of two arguments cumulatively to the items of iterable, from left to right, so as to reduce the iterable to a single value.chr()
- Return a string of one character whose ASCII code is the integer i.frozenset()
- Return a newfrozenset
object, optionally with elements taken from iterable.frozenset
is a built-in class.
class frozenset([iterable])
reload()
- Reload a previously imported module.vars()
- Return the__dict__
attribute for a module, class, instance, or any other object with a__dict__
attribute.classmethod()
- Return a class method for function.getattr()
- Return the value of the named attribute of object. name must be a string.map()
- Applies a callable to each item in collection in the second argument.
>>> map(lambda x: x * 2, [5, 6, 7, 8]) [10, 12, 14, 16] >>>
Also, maps can be expressed as list comprehensions:
>>> [x * 2 for x in [5, 6, 7, 8]] [10, 12, 14, 16] >>>
repr()
- Return a string containing a printable representation of an object.xrange()
- Likerange()
but returns an iterator instead of just a list.cmp()
- Compare the two objects x and y and return an integer according to the outcome.globals()
- Return a dictionary representing the current global symbol table.max()
- Returns the maximum value from the collection passed in.
>>> max([6,5,4,3]) 6
reversed()
- Return a reverse iterator.zip()
- This function returns a list of tuples, where the i-th tuple contains the i-th element from each of the argument sequences or iterables.compile()
- Compile the source into a code or AST object.hasattr()
- The arguments are an object and a string. The result isTrue
if the string is the name of one of the object’s attributes,False
if not.memoryview()
- Return a “memory view” object created from the given argument.round()
- Return the floating point value number rounded to ndigits digits after the decimal point._import__()
- The function imports the module name, potentially using the given globals and locals to determine how to interpret the name in a package context.
__import__(name[, globals[, locals[, fromlist[, level]]]])
complex()
- Return a complex number with the value real + imag1j or convert a string or number to a complex number.hash()
- Return the hash value of the object (if it has one).min()
- Returns the minimum value from the collection passed in.
>>> min([6,5,4,3]) 3
delattr()
- This is a relative ofsetattr()
. The arguments are an object and a string.help()
- Invoke the built-in help system.next()
- Retrieve the next item from the iterator by calling itsnext()
method.setattr()
- This is the counterpart ofgetattr()
. The arguments are an object, a string and an arbitrary value.hex()
- Convert an integer number (of any size) to a lowercase hexadecimal string prefixed with "0x".
>>> hex(255) '0xff' >>> hex(-42) '-0x2a' >>> hex(1L) '0x1L'
object()
- Return a new featureless object.object
is a base for all new style classes.slice()
- Return a slice object representing the set of indices specified byrange(start, stop, step)
.dir()
- Without arguments, return the list of names in the current local scope. With an argument, attempt to return a list of valid attributes for that object.id()
- Return the “identity” of an object.oct()
- Convert an integer number (of any size) to an octal string.sorted()
- Returns a copy of the passed in list sorted.
>>> sorted([9,4,1,8,4,6]) [1, 4, 4, 6, 8, 9]
keywords
- False
- await
- else
- import
- pass
- None
- break
- except
- in
- raise
- True
- class
- finally
- is
- return
- and
- continue
- for
- lambda
- try
- as
- def
- from
- nonlocal
- while
- assert
- del
- global
- not
- with
- async
- elif
- if
- or
- yield
global gen def gen(): yield 1 yield 2 yield 'x' @taxa.route("/f") def f(): response.add(str(list(gen()))) # [1, 2, 'x']