I have worked with Django for a while but I am new to xml-rpc. I have two Django servers running and the first needs to call functions from some modules of second server. I find xml-rpc easiest way to do so but don't want to run a separate server for this only.
What options do I have? Can I run Django's web-server and xml-rpc server with a single manage runserver command ?
Easily - we use http://code.djangoproject.com/wiki/XML-RPC to add an xml-rpc server into our django server.
You may also consider David Fisher's rpc4django which supports both XMLRPC and JSONRPC within a single package. Features include:
Detects request type (JSONRPC or XMLRPC) based on content
Easy identification of RPC methods via a decorator
Pure python and requires no external modules except Django
Customizable RPC method documentation including reST
Supports XMLRPC and JSONRPC introspection
Supports method signatures (unlike SimpleXMLRPCServer)
Easy installation and integration with existing Django projects
Ties in with Django’s authentication and authorization
Try: http://pypi.python.org/pypi/django-xmlrpc
Related
I have a RESTful service which was written using the Python asynchronous web framework Tornado
I am trying to support API versioning inside my RESTful service, so I can support simultaneous versions of the same API.
One clear way is to simply add the version to the URL path and route each path to a different API class, as follows:
http://mydomain/api/v2/myapi/myarg
http://mydomain/api/v1.1/myapi/myarg
http://mydomain/api/v1/myapi/myarg
But this will result in a tangled and duplicated code.
Another way would be to get the version by header, and check the version inside the API class, and operate accordingly.
This way is also not very native, and seems like a patch to solve the use of API versioning.
It will force me to call the "IF-SWITCH" code that checks the version explicitly in each API class.
Is there a way to do API versioning in Tornado in a more native way?
(where the versioning is treated using some hidden Tornado code, such that is done with other Tornado decorators).
I have built a web platform with Django. Users with Staff status can log into Django-admin through their web browsers and add, remove or alter different objects, upload files, etc.
Now I want to build a command line tool to enable users to do these tasks via command line. The users need to authenticate in command line, and then use different commands to perform their target operation.
Think a command line git client to github.
Of course it's possible to authenticate and send form data using request or cURL. But is there any standard, better way of doing this? Is there any utility/library for this, maybe a Django/python one?
This looks like a '2-component' thing.
API
You will have to expose the desired functionality via an (RESTful) API.
Two common and very good libraries are tastypie and Django REST Framework.
They help you building APIs in a fast and flexible way - think about it as 'Django admin' for APIs.
Client
For request handling I would suggest to have a look at the python-requests library.
PS:
If you're interested - we did build a (quick, ugly, dirty & buggy) python client that interacts with our Django based service platform. You can find it on GitHub
We've got a couple of quite complex sites written in Python based on Django, hosted by uwsgi. We also use nginx for some out-of-application things (like SSL termination).
I need to write an incredibly lightweight API which does nothing except validate an authentication token (against a different API) and respond with some info from the local file system.
I'd prefer to avoid using a whole Django site for what will be ~50 lines of code, however, since I develop on a windows machine, I'm not sure how best to host this tiny API for dev/testing. (Django's runserver command usually handles this for us) uWSGI seems like a good choice for final usage as it's already in use elsewhere but doesn't run on Windows.
I could always just code on one box, deploy and then test but it seems a little long-winded. Ideally, whatever I can find to host on windows will call my code in the same way as uwsgi
What's the best way to do this?
The most lightweight would be wsgiref.simple_server from the standard library which Django's runserver command uses internally.
Alternatively you can use
WSGI server from the Paste
This is a minimalistic WSGI server using Python’s built-in
BaseHTTPServer; if pyOpenSSL is installed, it also provides SSL
capabilities.
Waitress from the Pylons project
Waitress is meant to be a production-quality pure-Python WSGI server
with very acceptable performance. It has no dependencies except ones
which live in the Python standard library. It runs on CPython on
Unix and Windows under Python 2.6+ and Python 3.2+. It is also
known to run on PyPy 1.6.0 on UNIX. It supports HTTP/1.0 and HTTP/1.1.
WSGI server from CherryPy
A high-speed, production ready, thread pooled, generic HTTP server.
while I have quite some python experience, I've never used it for web and I have vast amount of web experience with PHP.
Now I want to create a simple python script (lets call it service.py) that runs on example.com. I installed mod_wsgi as suggested by the docs, my web server is Apache 2.2, the mod_wsgi is loaded successfully.
How do I configure my web server/mod_wsgi so that requests comming to example.com/service are processed by service.py?
Then how do I access the request params (like $_GET, $_POST, $_FILES) from the python script?
With mod_wsgi, you configure which URLs are served by setting WSGIScriptAlias. Your script, though, needs to be an actual WSGI application, which exposes an application variable which is called by the server.
I suspect it'd be easier to configure your script as simple CGI. You can then use the cgi module from the standard library to access your request params (note, though, that the examples you give are PHP-specific: they're accessed differently in Python, depending on the specific framework).
Another alternative would be to use a mini-framework like Flask, which would encapsulate all this and give you a simple interface to use in your service.py script.
Is there any lightweight mvc webframework which is not necessary to install to the server?
I need something simple, that i could just copy to the shared hosting. And it must handle urls other that localhost/test.py, something like this localhost/Blog/test
You should probably check out Flask or Bottle, two nice Python microframeworks. With an appropriate "main" Python script (to initialize your app and dispatch requests to it) and mod_rewrite rules in place, you can probably get pretty close to your goal of "just copy[ing] to the shared hosting" with nice URLs.
Flask has good documentation on deploying via CGI, which is what you might have to use on your shared host. (If your host supports FastCGI or mod_wsgi, those deployment options would be preferable.)
Checkout web2py. Seems to be about the simplest python based webserver I can think of.
Django might do, it's hefty, but it comes with it's own development server.
web2py includes everything (ssl-enabled web server, sqlite sql based transaction safe database, web based Integrated Development Enviroment, web based database interface) in one package. The web2py binaries for windows and mac also include Python itself. web2py does not require configuration or installation and can run off a usb drive. It was originally developed as a teaching tool for MVC.
checkout https://github.com/salimane/bottle-mvc or https://github.com/salimane/flask-mvc . They are boilerplates that could get you started with controllers, models in separate folders. They are based on bottle and flask micro frameworks, no useless features, they give you the flexibility to plugin whatever modules you want.