background preloader

Python

Facebook Twitter

15.5. optparse — Parser for command line options. New in version 2.3. Deprecated since version 2.7: The optparse module is deprecated and will not be developed further; development will continue with the argparse module. optparse is a more convenient, flexible, and powerful library for parsing command-line options than the old getopt module. optparse uses a more declarative style of command-line parsing: you create an instance of OptionParser, populate it with options, and parse the command line. optparse allows users to specify options in the conventional GNU/POSIX syntax, and additionally generates usage and help messages for you.

With these few lines of code, users of your script can now do the “usual thing” on the command-line, for example: As it parses the command line, optparse sets attributes of the options object returned by parse_args() based on user-supplied command-line values. Where the value of yourscript is determined at runtime (normally from sys.argv[0]). 15.5.1. 15.5.1.1. Argument option option argument positional argument. Introduction to Celery — Celery 3.1.7 documentation. What is a Task Queue? Task queues are used as a mechanism to distribute work across threads or machines. A task queue’s input is a unit of work, called a task, dedicated worker processes then constantly monitor the queue for new work to perform. Celery communicates via messages, usually using a broker to mediate between clients and workers.

To initiate a task a client puts a message on the queue, the broker then delivers the message to a worker. A Celery system can consist of multiple workers and brokers, giving way to high availability and horizontal scaling. Celery is written in Python, but the protocol can be implemented in any language. So far there’s RCelery for the Ruby programming language, node-celery for Node.js and a PHP client, but language interoperability can also be achieved by using webhooks. What do I need? Celery requires a message transport to send and receive messages. Celery can run on a single machine, on multiple machines, or even across data centers. Installation Bundles. Django REST framework - APIs made easy. Django REST framework is a powerful and flexible toolkit that makes it easy to build Web APIs. Some reasons you might want to use REST framework: The Web browseable API is a huge usability win for your developers.Authentication policies including OAuth1a and OAuth2 out of the box.Serialization that supports both ORM and non-ORM data sources.Customizable all the way down - just use regular function-based views if you don't need the more powerful features.Extensive documentation, and great community support.Used and trusted by large companies such as Mozilla and Eventbrite.

Above: Screenshot from the browsable API Requirements REST framework requires the following: Python (2.6.5+, 2.7, 3.2, 3.3)Django (1.3, 1.4, 1.5, 1.6) The following packages are optional: Note: The oauth2 Python package is badly misnamed, and actually provides OAuth 1.0a support. Installation Install using pip, including any optional packages you want... ...or clone the project from github. INSTALLED_APPS = ( ... Example Tutorial. Table Of Contents — Tastypie 0.11.1-dev documentation. Introduction — virtualenv 1.10.1 documentation. Virtualenv is a tool to create isolated Python environments. The basic problem being addressed is one of dependencies and versions, and indirectly permissions. Imagine you have an application that needs version 1 of LibFoo, but another application requires version 2. How can you use both these applications? If you install everything into /usr/lib/python2.7/site-packages (or whatever your platform’s standard location is), it’s easy to end up in a situation where you unintentionally upgrade an application that shouldn’t be upgraded.

Or more generally, what if you want to install an application and leave it be? If an application works, any change in its libraries or the versions of those libraries can break the application. Also, what if you can’t install packages into the global site-packages directory? In all these cases, virtualenv can help you. Warning We advise installing virtualenv-1.9 or greater. When using pip to install virtualenv, we advise using pip 1.3 or greater. Note. Gevent-socketio documentation — gevent-socketio 0.3.1 documentation. Introduction¶ Socket.IO is a WebSocket-like abstraction that enables real-time communication between a browser and a server. gevent-socketio is a Python implementation of the protocol. The reference server implementation of Socket.IO runs on Node.js and was developed by LearnBoost.

There are now server implementations in a variety of languages. One aim of this project is to provide a single gevent-based API that works across the different WSGI-based web frameworks out there (Pyramid, Pylons, Flask, web2py, Django, etc...). Only ~3 lines of code are required to tie-in gevent-socketio in your framework. Note: you need to use the gevent python WSGI server to use gevent-socketio. Namespaces: since you mostly have one websocket/socket.io endpoint per website, it is important to be able to namespace the different real-time activities of the different pages or parts of your site, just like you need routes to map URLs to different parts of your code. Concepts¶ var socket = io.connect("/chat"); Twisted. Twisted is an event-driven networking engine written in Python and licensed under the open source ​MIT license. Twisted runs on Python 2 and an ever growing subset also works with Python 3.

Twisted makes it easy to implement custom network applications. Here's a TCP server that echoes back everything that's written to it: from twisted.internet import protocol, reactor, endpoints class Echo(protocol.Protocol): def dataReceived(self, data): self.transport.write(data) class EchoFactory(protocol.Factory): def buildProtocol(self, addr): return Echo() endpoints.serverFromString(reactor, "tcp:1234").listen(EchoFactory()) reactor.run() Learn more about ​writing servers, ​writing clients and the ​core networking libraries , including support for SSL, UDP, scheduled events, unit testing infrastructure, and much more. Twisted includes an event-driven web server. Learn more about ​web application development, ​templates and Twisted's ​HTTP client.

Twisted includes a sophisticated IMAP4 client library. Django-tagging - A generic tagging application for Django projects. A generic tagging application for Django projects, which allows association of a number of tags with any Model instance and makes retrieval of tags simple. The CHANGELOG is kept up to date with notable commits and the latest version of this application's documentation, in reStructuredText format, is always available in its overview.txt file or rendered nicely. Note: this documentation is for the SVN trunk version - it may differ from the documentation for the packaged release. Version 0.3 Features Version 0.3 was released on 22nd August 2009, packages from revision 158 in Subversion.

Works on 1.0 and other fixes. This release was made to provide a 1.0 compatible release (since one hasn't been made in over a year). Version 0.2 Features Version 0.2 was released on 12th January 2008, packaged from revision 122 in Subversion. Version 0.2.1, a bugfix release, was released on 16th January 2008 - this fixes a bug with space-delimited tag input. Requires a recent SVN checkout of Django's trunk. or. Python & Java: A Side-by-Side Comparison « Python Conquers The Universe. I wrote this little piece a long time ago — it was last updated in May 2007. In 2009 I moved it from my website to this blog. At this point I consider it an historical artifact, in the sense that I consider it frozen; I’m no longer going to update it when, for example, Java acquires a new programmer-friendly feature. During the years when it was on my web site, I received a number of email comments.

I responded to them all, but no one — other than their authors and me — ever saw the comments and my responses. By moving this piece onto a blog, I hope that folks who feel like commenting can do so more easily, and can share their comments with a wider audience. During the years when it was on my web site, virtually all of the comments that I received were from Java programmers. I was recently asked if I still hold the opinions that I expressed in this article. . — Steve Ferg Updated October 14, 2011 to fix a few minor typos How much more productive? The classic “Hello, world!” In Why Python? Dive Into Python.