Skip to content

zhouzhuojie/pyddp

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pyddp

Latest Version Downloads Egg Status Wheel Status Build Status License

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

Installation

Install via pip

$ pip install pyddp

Get started

  1. Create and activate a Python 2.7 virtualenv.

    $ virtualenv -p python2.7 venv
    $ . venv/bin/activate
  2. Install dependencies using pip.

    $ pip install -r requirements.txt
  3. Check that everything is works.

    $ nosetests
  4. Install Meteor and run the example Meteor project.

    $ cd example/meteor
    $ meteor
  5. In another terminal, activate the virtualenv (see step 1) and run the example script.

    $ PYTHONPATH=. python example/example.py
    Result: HELLO, WORLD!

Links

About

Distributed data protocol (DDP) for Python 2

Resources

License

Stars

Watchers

Forks

Packages

No packages published