Syntax reference card


Each Pythomnic3k module has the following format:
__all__ = [ "method" ] # methods accessible with pmnc calls

def method(...):


Calls between modules within one cage

To call one local module from another:
result = pmnc.module.method(...)
To enqueue a retriable call (returns immediately, runs later):
retry_id = pmnc(queue = "retry").module.method(...)

Calls between cages

To execute synchronous RPC call:
result = pmnc("other_cage").module.method(...)
To send asynchronous reliable message (with retriable call semantics):
retry_id = pmnc("other_cage", queue = "retry").module.method(...)

Resource transactions

To engage one or more resource in a transaction:
xa = pmnc.transaction.create()
result1, result2 = xa.execute()
The shortcut syntax for transactions with just one participant:
result = pmnc.transaction.resource.execute(...)
More specifically, here is an example of a database query:
xa = pmnc.transaction.create()
xa.some_db.execute("SELECT foo FROM bar WHERE key = {value}",
                   value = 123)
records = xa.execute()[0][0]
for r in records:
    foo = r["foo"]
and this is an example of SMS being sent:
message_id = pmnc.transaction.\
    smpp_prov.submit(destination_addr = "79876543210",
                     short_message = "hello")

Persistent state

To access persistent state private to each cage's module:
pmnc.state.set(key, value)
value = pmnc.state.get(key, default)


Each module ( may have its own configuration file ( and access it like this:
value = pmnc.config.get(key, default)
And the configuration file itself simply contains a dict:
config = dict \
key = "value",


To write to a local cage's log file:
pmnc.log.debug("Don't bother reading this")"This is mildly interesting")
pmnc.log("This says something relevant")
pmnc.log.warning("Something's not right")
pmnc.log.error("Definetely !")
To send a message to a health monitor:"Situation normal")
pmnc.notify.warning("Uhm... it's getting worse")
pmnc.notify.error("Call the administrator")
pmnc.notify.alert("Now !")
Logging level can be temporarily increased using
with pmnc.log.level("DEBUG"):

Special constants

Name of the current cage:
pmnc.log(__cage__) # somecage
Name of the current server (node):
pmnc.log(__node__) # cruncher
Cage's private directory:
pmnc.log(__cage_dir__) # /pythomnic3k/cages/somecage