{ "info": { "author": "Arnaud Grausem", "author_email": "arnaud.grausem@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.2", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6" ], "description": "=======\nBritney\n=======\n\nBritney is a module that implements the `SPORE specification`_. It is based on `Spyre`_.\nThis module requires a SPORE description of an API. Some descriptions for known services are available `here`_. You can write your own with `this guide`_.\n\n.. _SPORE specification: https://github.com/SPORE/specifications/blob/master/spore_implementation.pod\n.. _Spyre: https://github.com/bl0b/spyre\n.. _here: https://github.com/spore/api-description\n.. _this guide: https://github.com/SPORE/specifications/blob/master/spore_description.pod\n\n.. image:: https://secure.travis-ci.org/agrausem/britney.png?branch=master\n :target: https://travis-ci.org/agrausem/britney\n\n.. image:: https://coveralls.io/repos/agrausem/britney/badge.png?branch=master\n :target: https://coveralls.io/r/agrausem/britney?branch=master\n\n.. image:: https://img.shields.io/pypi/v/britney.svg\n :target: https://pypi.python.org/pypi/britney\n\n.. image:: https://img.shields.io/pypi/dm/britney.svg\n :target: https://pypi.python.org/pypi/britney\n\n.. image:: https://landscape.io/github/agrausem/britney/master/landscape.svg?style=flat\n :target: https://landscape.io/github/agrausem/britney/master\n :alt: Code Health\n\n.. image:: https://img.shields.io/pypi/pyversions/britney.svg\n :target: https://pypi.python.org/pypi/britney\n :alt: Python Version\n\n.. image:: https://img.shields.io/pypi/format/britney.svg\n :target: https://github.com/agrausem/britney/\n\nInstall\n=======\n\nBritney is working under Python 2.7 and Python >= 3.2. To install the module, you should use pip or easy_install : ::\n\n $> pip install britney\n\nor ::\n\n $> easy_install britney\n\n\nCreate your client\n==================\n\nBasics\n------\n\nYou must create your client with the **new** method that reads a json file containing the API description or an URI exposing the description. This can be done like that : ::\n\n import britney\n\n # from a description file\n client = britney.new('/path/to/api_desc.json')\n\n # from an URI\n client = britney.new('http://my-server/ws/api_desc.json')\n\n\nThe base URL\n------------\n\nIf your API description file doesn't specify the base URL of the service, you can pass it to the **new** as the named argument **base_url** : ::\n\n import britney\n\n client = britney.new('/path/to/api_desc.json', base_url='http://my-server/ws/api/')\n\nMiddlewares\n-----------\n\nSometimes, services need credentials to let you access the data or even send data. The client you created can enable middlewares at runtime and also extend his usage, by doing this : ::\n\n import britney\n from britney.middleware import auth\n\n client = britney.new('http://my-server/ws/api_desc.json')\n client.enable(auth.Basic, username='login', password='xxxxxx')\n\nSometimes, you want to enable middlewares on certain conditions. Another method called **enable_if** can take a callable predicate as argument that can check the environment parameters of the request : ::\n\n import britney\n from britney.middleware import auth \n\n client = britney.new('http://my-server/ws/api_desc.json')\n client.enable_if(lambda request: request['payload'] != '', auth.Basic, username='login', password='xxxxxx')\n\n\nUse your client\n===============\n\nAccess data\n-----------\n\nSend data\n---------\n\nA full example\n--------------\n\nCreate your own middleware\n==========================\n\nBasics\n------\n\nCreating and enabling middlewares let you control how request are send or response are received by adding authentification or formatting data. To create your middleware, you should :\n\n * inherit from ``britney.middleware.Middleware``\n * define how to instantiate your middleware\n * implement the process_request method to process the request\n * implement the process_response method to process the response\n\nHere is a base class example to perform runtime on request : ::\n\n from britney.middleware import Middleware\n\n\n class Runtime(Middleware):\n\n def __init__(self, runtime_header):\n self.runtime_header = runtime_header\n\n def process_request(self, environ):\n pass\n\n def process_response(self, response):\n pass\n\n\nProcessing request\n------------------\n\nWith this method, you can access all of the keys and values of the request's base environment. By the way, you can add keys and values, change them or even delete them. Most of time, this method doesn't return data but if you return a requests.Response object, the process will stop and return this response. The result environment data will be used to build the request : :: \n\n import datetime\n\n [...]\n\n def process_request(self, environ):\n self.start_time = datetime.datetime.now()\n environ[self.runtime_key] = 0\n\nProcessing response\n-------------------\n\nWith this method, you can access data from the response, change or format content or even check headers or status : ::\n\n [...]\n\n def process_response(self, reponse):\n request_time = datetime.datetime.now() - self.start_time\n response.environ[self.runtime_key] = self.request_time.seconds\n\nUse it\n------\n\nWhen you create your client, you only should enable your middleware and pass appopriate **named arguments** to the ``enable`` method : ::\n\n import britney\n from your_module.middleware import Runtime\n\n client = britney.new('http:://server.org/ws/api.json')\n client.enable(Runtime, runtime_key='X-Spore-Runtime')\n\n\nThat's all !\n\n\nTest it\n-------\nA mock middleware and a function to fake ``Requests`` response are available to test the middlewares you created by faking a server. To test the Runtime middleware, you can do as follow : ::\n\n import datetime\n import unittest\n import britney\n from britney.middleware import utils\n from your_module.middleware import Runtime\n\n def test_response(request):\n return utils.fake_response(request, 'OK')\n\n class TestRuntime(unittest.TestCase):\n\n def setUp(self):\n self.fake_server = {'/test', test_response}\n self.client = britney.new('/path/to/api.json')\n self.runtime_key = 'X-Spore-Runtime'\n\n def test_runtime(self):\n self.client.enable(Runtime, runtime_header=self.runtime_header)\n self.client.enable(utils.Mock, fakes=self.fake_server, middlewares=self.client.middlewares)\n start = datetime.datetime.now()\n result = self.client.test()\n stop = datetime.datetime.now()\n\n self.assertIn(result.environ, self.runtime_key)\n self.assertAlmostEqual(result.environ[self.runtime_key], (stop - start).seconds)\n\n\n", "description_content_type": null, "docs_url": null, "download_url": "http://pypi.python.org/pypi/britney", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/agrausem/britney", "keywords": "SPORE,REST Api,client", "license": "PSF", "maintainer": "", "maintainer_email": "", "name": "britney", "package_url": "https://pypi.org/project/britney/", "platform": "", "project_url": "https://pypi.org/project/britney/", "project_urls": { "Download": "http://pypi.python.org/pypi/britney", "Homepage": "https://github.com/agrausem/britney" }, "release_url": "https://pypi.org/project/britney/0.5.1/", "requires_dist": [ "requests", "requests-testadapter" ], "requires_python": "", "summary": "Python implementation of SPORE", "version": "0.5.1" }, "last_serial": 2611223, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "14fb38ab7b034ce21bc8abadfc317796", "sha256": "a19fa82dd42a71e0aad368d90e99e32acea3ddae1df382eae143132ebbd5aeac" }, "downloads": -1, "filename": "britney-0.1.tar.gz", "has_sig": true, "md5_digest": "14fb38ab7b034ce21bc8abadfc317796", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6769, "upload_time": "2013-09-13T18:53:29", "url": "https://files.pythonhosted.org/packages/41/2b/e4afa5375bf6e7c215c7180146f497c04b61cd63e29de69b690c6f83f3b7/britney-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "a4fd18cfba61490d3f6d27ec29cdf59e", "sha256": "c3a5159ca9f2db4acc5bf32c5ed74f2d1749450924ca37f4a25e2a53adf20263" }, "downloads": -1, "filename": "britney-0.2.tar.gz", "has_sig": false, "md5_digest": "a4fd18cfba61490d3f6d27ec29cdf59e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11593, "upload_time": "2013-11-07T08:21:10", "url": "https://files.pythonhosted.org/packages/eb/d6/7fc19ec42bb9732bda401b54834f811b03487de67b1d12fb8f0b845c75fa/britney-0.2.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "49338139a06804b250e1a522f2242f3f", "sha256": "6e3d4b37a069abfb5621d41655bbc3243d0f5aca750febf582ff503908513482" }, "downloads": -1, "filename": "britney-0.2.1.tar.gz", "has_sig": false, "md5_digest": "49338139a06804b250e1a522f2242f3f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11646, "upload_time": "2013-11-08T10:24:23", "url": "https://files.pythonhosted.org/packages/06/18/053f4b3276b896d85b2bca2e6882895302377e181e389adfbb7947218ee4/britney-0.2.1.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "64bf7977aeeeb99b4a37f9e96c929bfe", "sha256": "b546bc3ad28dd29746d4e972ce17940acff98c33f4051d671a731998156e5ec9" }, "downloads": -1, "filename": "britney-0.3.0.tar.gz", "has_sig": false, "md5_digest": "64bf7977aeeeb99b4a37f9e96c929bfe", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11999, "upload_time": "2013-12-05T10:16:25", "url": "https://files.pythonhosted.org/packages/85/d1/32b8814c073acf2dceb649be74519705e574135a904d54a2644034a0e14c/britney-0.3.0.tar.gz" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "b59bb21fa385ae15f031aa1e8d059d56", "sha256": "ea1b4b840e965b0aed7da9c3d1e8c206814f569fe276644ab787d009f8e30d6d" }, "downloads": -1, "filename": "britney-0.3.1.tar.gz", "has_sig": false, "md5_digest": "b59bb21fa385ae15f031aa1e8d059d56", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10047, "upload_time": "2014-04-15T20:21:43", "url": "https://files.pythonhosted.org/packages/b2/4e/49d2d4884803bbb17e175692831d9e04832628cd6ab2a0dee0a4c7267b5d/britney-0.3.1.tar.gz" } ], "0.3.2": [ { "comment_text": "", "digests": { "md5": "d9e1075944cfdd6d47b6446b76e542bc", "sha256": "0d26215bdd90126071182e2d6f4d213fbab6a29b9054c435f1f00125c51aa2cf" }, "downloads": -1, "filename": "britney-0.3.2.tar.gz", "has_sig": false, "md5_digest": "d9e1075944cfdd6d47b6446b76e542bc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10664, "upload_time": "2014-04-29T18:08:15", "url": "https://files.pythonhosted.org/packages/ac/aa/bbc76ff64705a9efa4bd221b5b25dda10822799da948110561567acd3d5a/britney-0.3.2.tar.gz" } ], "0.3.3": [ { "comment_text": "", "digests": { "md5": "4d9abe638e9396d370259649eaa0d1c8", "sha256": "47c157c93fba421aac5a7243c23c9450fc39af574156c1361ae3bfa225b0998e" }, "downloads": -1, "filename": "britney-0.3.3.tar.gz", "has_sig": false, "md5_digest": "4d9abe638e9396d370259649eaa0d1c8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12797, "upload_time": "2014-06-11T14:21:26", "url": "https://files.pythonhosted.org/packages/47/49/845a6a27d2ceb37c23c82f8a45bdf177e3d7f4ed7516ec98d88ca2392c69/britney-0.3.3.tar.gz" } ], "0.4.0": [ { "comment_text": "", "digests": { "md5": "4f918b904e95854ad60d7b106b0f4271", "sha256": "d86afe562177f4871c25cdd6bccf72b099b5cdba319d55b0726ab81087071d03" }, "downloads": -1, "filename": "britney-0.4.0.tar.gz", "has_sig": false, "md5_digest": "4f918b904e95854ad60d7b106b0f4271", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10976, "upload_time": "2014-12-05T22:42:28", "url": "https://files.pythonhosted.org/packages/4f/db/eb04c135ad8a384a954d8b826d291f85dfa0f43ae4aa630dcead3d6dcad3/britney-0.4.0.tar.gz" } ], "0.5.0": [ { "comment_text": "", "digests": { "md5": "e9bbf896901c3cd6d5ee60d6ef12e12d", "sha256": "0d5c468883dfcc5b61990d6835beacc8e685b1f61fa41025aa0ca59ef82eb1c0" }, "downloads": -1, "filename": "britney-0.5.0.tar.gz", "has_sig": false, "md5_digest": "e9bbf896901c3cd6d5ee60d6ef12e12d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13288, "upload_time": "2015-07-20T07:39:00", "url": "https://files.pythonhosted.org/packages/9a/a9/df4ae90483d4d7e41fedde41ca84930841925906e77e089ab0ff4ec723ff/britney-0.5.0.tar.gz" } ], "0.5.1": [ { "comment_text": "", "digests": { "md5": "4e3cb91e603e24d01c2ff1c25ff8caa7", "sha256": "680faf36f00865ab77dbb7a092d34ed3bbf7f3da018a37e6eb8207aebd01a942" }, "downloads": -1, "filename": "britney-0.5.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "4e3cb91e603e24d01c2ff1c25ff8caa7", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 16719, "upload_time": "2017-02-01T10:43:17", "url": "https://files.pythonhosted.org/packages/71/af/d83b5e5a3bc83c22b670b5a549101ad236dc7e7035f23743d892f26600d7/britney-0.5.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8b93a82cae47eacebc5df0c13e7c2f93", "sha256": "6e2c461ede290246b777dc1444fcf5823234825d7746f6d6aabc4793340d2e3b" }, "downloads": -1, "filename": "britney-0.5.1.tar.gz", "has_sig": false, "md5_digest": "8b93a82cae47eacebc5df0c13e7c2f93", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11395, "upload_time": "2017-02-01T10:43:18", "url": "https://files.pythonhosted.org/packages/61/0a/0a7732d5f43a8313546941f640bd54f9b8cc540c286d4da7394e675576ff/britney-0.5.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "4e3cb91e603e24d01c2ff1c25ff8caa7", "sha256": "680faf36f00865ab77dbb7a092d34ed3bbf7f3da018a37e6eb8207aebd01a942" }, "downloads": -1, "filename": "britney-0.5.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "4e3cb91e603e24d01c2ff1c25ff8caa7", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 16719, "upload_time": "2017-02-01T10:43:17", "url": "https://files.pythonhosted.org/packages/71/af/d83b5e5a3bc83c22b670b5a549101ad236dc7e7035f23743d892f26600d7/britney-0.5.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8b93a82cae47eacebc5df0c13e7c2f93", "sha256": "6e2c461ede290246b777dc1444fcf5823234825d7746f6d6aabc4793340d2e3b" }, "downloads": -1, "filename": "britney-0.5.1.tar.gz", "has_sig": false, "md5_digest": "8b93a82cae47eacebc5df0c13e7c2f93", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11395, "upload_time": "2017-02-01T10:43:18", "url": "https://files.pythonhosted.org/packages/61/0a/0a7732d5f43a8313546941f640bd54f9b8cc540c286d4da7394e675576ff/britney-0.5.1.tar.gz" } ] }