I would like to build a project in meteor
(version 0.8) that calls a python
script which in turn sends some data back to meteor
. I am not sure what the best practice is for doing this at the moment.
DDP looks good:
"Clients that can be used to communicate with Meteor through it's DDP protocol, from outside the Meteor stack." But the python
implementation looks unfinished: python-ddp-client
I guess I could also write directly to mongodb
from python
but it doesn't sound like the best idea:
Am I missing anything? Is there a better way to do this?
If the python script is on the same server you could just call it like in a normal Node.js application:
var exec = Npm.require('child_process').exec;
var Fiber = Npm.require('fibers');
var Future = Npm.require('fibers/future');
Meteor.methods({
callPython: function() {
var fut = new Future();
exec('pythonScriptCommand with parameters', function (error, stdout, stderr) {
// if you want to write to Mongo in this callback
// you need to get yourself a Fiber
new Fiber(function() {
...
fut.return('Python was here');
}).run();
});
return fut.wait();
},
});
The other questions you linked to are very out of date (one is almost two years old).
You should just write directly to MongoDB from python, if you don't need to call server methods. In fact, this is how multiple Meteor servers (load-balancing the same app) talk to each other. This is implemented by having Meteor servers tail the Mongo oplog and incorporate any database operations immediately.
This was fully implemented in Meteor version 0.7.2.
When you write to the database, you can use the typical observe
or observeChanges
operations on collections to have the Meteor server do stuff.
Another way to make RPC calls is to use a messaging bus such as ZeroMQ. I'm using this to call machine learning algorithms in Python from Meteor. This supports Python processes on different machines, load balancing, and the like. See the following post for how to do so:
http://ianhinsdale.com/code/2013/12/08/communicating-between-nodejs-and-python/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With