Warning
This library is still in the planning stage. If you use
it, please use a specific version, e.g.., in your requirements.txt
add the line;
pyddp==0.2.2
Connect to a DDP server (e.g., a Meteor server)
# Import the DDP package.
import ddp
# Create a client, passing the host and port of the server.
client = ddp.DdpClient('127.0.0.1:3000')
# Once enabled, the client will maintain a connection to the server.
client.enable()
Call a method
Assume your Meteor server has the following method.
Meteor.methods({
upper: function (text) {
check(text, String);
return text.toUpperCase();
}
});
# The method is executed asynchronously.
future = client.call('upper', 'Hello, World1')
# ... Do something else ...
# Block until the result message is received.
result_message = future.get()
# Check if an error occured else print the result.
if result_message.has_error():
print result_message.error
else:
print result_message.result
Automatic reconnection
If the connection to the server goes down, the client automatically attempts to reconnect.
Ponger
Automatically responds to pings from the server.
Debugging
client = ddp.DdpClient('127.0.0.1:3000', logging=True)
Coming soon (i.e., not implemented)
- Automatic resend after reconnection
- DDP server
- Outboxing
- Random seeds
- Sensible reconnection delay (i.e. exponential back-off)
- Subscriptions
Install via pip
$ pip install pyddp
-
Create and activate a Python 2.7 virtualenv.
$ virtualenv -p python2.7 venv $ . venv/bin/activate
-
Install dependencies using
pip
.$ pip install -r requirements.txt
-
Check that everything is works.
$ nosetests
-
Install Meteor and run the example Meteor project.
$ cd example/meteor $ meteor
-
In another terminal, activate the virtualenv (see step 1) and run the example script.
$ PYTHONPATH=. python example/example.py Result: HELLO, WORLD!