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.4.0
I (well, Foxdog Studios) improve this library on an as-needed basis. That is, I add something when we (Foxdog Studios) require it. If you'd like a feature, create an issue. The advantage of this is that we use every feature (in our stage show) and so it gets tested regularly. I've kept the API very thin, the feature you want might already be supported and I'll just expose it nicely.
Connect to a Meteor DDP server
# Import the DDP package.
import ddp
# Create a client, passing the URL of the server.
client = ddp.ConcurrentDDPClient('ws://127.0.0.1:3000/websocket')
# Once started, the client will maintain a connection to the server.
client.start()
# ... Do something with it ...
# Ask the client to stop and wait for it to do so.
client.stop()
client.join()
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, World!')
# ... 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.
Outbox
Call a method while the client was not connected? Do not fear, for pyddp's outbox will store the message until there is a connection.
Debugging
ddp.ConcurrentDDPClient(url, debug=True)
Not implemented
- Automatic resend after reconnection
- DDP server
- Random seeds
- Sensible reconnection delay (i.e. exponential back-off)
- Subscriptions
Install via pip
$ pip install pyddp
from ddp.pubsub.future import Future
future = Future()
# Wait for result forever (interruptable).
result = future.get()
# Wait for result for at most 1 second (interruptable).
from ddp.pubsub.timeout_error import TimeoutError
try:
result = future.get(timeout=1)
except TimeoutError:
print 'Took too long'