RPC for python functions in a Django project

28 צפיות
מעבר להודעה הראשונה שלא נקראה

Muhammad Choudry

לא נקראה,
17 באוג׳ 2011, 14:18:4617.8.2011
עד Django users
Hi,

I'm in the middle of trying to create a django website to access data
in a MySQL database. The intenion is to also create a UI in Dojo
(javascript). Also I would like the django backend will also provide
webservices (RPC for python functions) to allow access to the MySQL
database remotely. So for example, if someone wants to use Perl
scripts to access the database (and additional functionality like
calculations based off of data in the database) they can do so in
their native language.

Now ideally, the web services API is the same for javascript as well
as another remote service that wants to access these services. I've
found that JSON-RPC is a good way to go for this, as there is
typically built in support for this in javascript in addition to the
numerous additional benefits.

I've seen several ways to do this:
1) Create a unique URI for each function that you would like to
access:
https://code.djangoproject.com/wiki/JSONRPCServerMiddleware
2) Create one point of access, and pass the method name in the JSON
package. In this particular example an SMD is automatically
generated.
https://code.djangoproject.com/wiki/Jsonrpc

The issue with (1) is that if there are many functions to be accessed,
then there will be many URI's that will be used. This does not seem
like an elegant solution. The issue with (2) is that I need to
compare functions against a list of all functions. Again this is not
an elegant solution either.

Is there no way that we can take the advantages of (1) and (2) to
create an interface such that:
- Only one URI is used as a point of access
- Functions are called directly (without having to be compared
against a list of functions)

?

Gelonida N

לא נקראה,
17 באוג׳ 2011, 17:43:4217.8.2011
עד django...@googlegroups.com
Hi Muhammad,


On 08/17/2011 08:18 PM, Muhammad Choudry wrote:
> I've
> found that JSON-RPC is a good way to go for this, as there is
> typically built in support for this in javascript in addition to the
> numerous additional benefits.
>
> I've seen several ways to do this:
> 1) Create a unique URI for each function that you would like to
> access:
> https://code.djangoproject.com/wiki/JSONRPCServerMiddleware
> 2) Create one point of access, and pass the method name in the JSON
> package. In this particular example an SMD is automatically
> generated.
> https://code.djangoproject.com/wiki/Jsonrpc
>
> The issue with (1) is that if there are many functions to be accessed,
> then there will be many URI's that will be used. This does not seem
> like an elegant solution. The issue with (2) is that I need to
> compare functions against a list of all functions. Again this is not
> an elegant solution either.
>
> Is there no way that we can take the advantages of (1) and (2) to
> create an interface such that:
> - Only one URI is used as a point of access
> - Functions are called directly (without having to be compared
> against a list of functions)
>
> ?
>

Did you look at rpc4django.

The way it works roughly:
- you add rpc4django to the installed apps
- in urls.py you create one uri for the rpc calls
- you simply decorate all functions, that should be available via RPC.

By default the function will be available as xmlrpc and jsonrpc function.

For more details: http://packages.python.org/rpc4django/setup.html


Muhammad Choudry

לא נקראה,
18 באוג׳ 2011, 10:34:2818.8.2011
עד Django users
Thanks! This module didn't come across in my search.

I just skimmed through the files and it seems as if the module doesn't
support automatic SMD generation. Is this true?

David

לא נקראה,
18 באוג׳ 2011, 12:16:5018.8.2011
עד Django users
I'm the developer of rpc4django. The package does support SMD
generation and it makes it available in the system.describe() method
by default. However, JSONRPC is not nearly as well defined as XMLRPC
and nobody seems to agree exactly how an SMD should look let alone
what SMD even stands for. I tried to stick fairly close to the draft
specs, but it's somewhat of a moving target.



On Aug 18, 7:34 am, Muhammad Choudry <muhammadchou...@gmail.com>
wrote:
השב לכולם
השב למחבר
העבר לנמענים
0 הודעות חדשות