{ "info": { "author": "Samir Omerovic", "author_email": "somerovi@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy" ], "description": "Cosmicray\n=========\n\n------------------------------------------------------------------------\n Develop a client for any http API and document its quirks and features\n------------------------------------------------------------------------\n\nCosmicray is a simple and high level http client API development framework. It provides the basic building blocks for\ndefining enpoints, handling a request response and automatically converting the result into to Models.\n\nMotivation:\n\n- Ease of use\n- Configureability and customization on every level\n- Namespace different backends (one client to rule them all)\n- Separate route definitions / response handling from models or \"business logic\"\n- Ability to validate requests before making them\n- Authenticate each request as needed\n- Ability to associate routes to models\n\n.. warning::\n\n Cosmicray is under development\n\nInstall\n-------\n\n.. code::\n\n $ pip install cosmicray\n\nQuick start\n-----------\n\nCreate App\n~~~~~~~~~~\n\n.. code:: python\n\n >>> from cosmicray import Cosmicray\n >>> api = Cosmicray('myapp', domain='http://mydomain.com')\n\nDefine routes and response handlers\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nUsing the app we created, we can now add routes for it and define a response handler for each one. The response handler is simply a regular function that accepts a single argument of type `requests.Response` and returns the processed result.\n\n.. code:: python\n\n >>> @api.route('/v1/dogs/{id}', ['GET', 'POST', 'PUT', 'DELETE'])\n >>> def dogs(response):\n ... return response.json()\n\n- The decorator `api.route` creates an instance of `cosmicray.Route` named `dogs`\n and stores the given function internally as the response handler.\n\n- Instances of `cosmicray.Route` are callable and accept parameters:\n\n - `model_cls`: Optional: Class that implements `_make(cls, response)` classmethod.\n - `\\*\\*kwargs`: Keyword arguments.\n\n - `urlargs`: Mapping for url formatting arguments\n - `headers`: Mapping for headers\n - `params`: Mapping for query parameters\n - `data`, `json`, `files`: Request body\n - `authenticator`: Authenticator callback\n - *&rest*: Requests keyword arguments\n\n\n- When and instance of `cosmicray.Route` is called, it returns a `Request` object and with this you can:\n\n - Use functions defined for each http method (ex: `get()`, `post()`, `put()`, `delete()`)\n - Override any parameters passed in (ex: `params`, `headers`, etc.) with setters\n - Automatically validates given parameters against the defined parameters on the `Route`\n - Authenticates the request, if the app was configured with an authenticator\n - After the response is handled by the response handler, the result is automatically mapped to the model class, if one was provided\n\nHow to make requests\n~~~~~~~~~~~~~~~~~~~~\n\n.. code:: python\n\n >>> dogs().get()\n >>> dogs(urlargs={id: 12345}).get()\n >>> dogs(json={'name': 'Manu'}).post()\n >>> dogs(urlargs={'id': 12345}, json={'age': 4}).put()\n >>> dogs(urlargs={'id': 12345}).delete()\n\nTo specify request parameters\n\n.. code:: python\n\n >>> dogs(params={'breed': 'husky'},\n ... headers={'Content-Type': 'application/json'}).get()\n\nAuthenticating requests\n~~~~~~~~~~~~~~~~~~~~~~~\n\nOften you'll need to authenticate requests to access private resource and Cosmicray has a built-in mechanism to perform this step.\n\n.. code:: python\n\n >>> def authenticator(request):\n ... if not request.is_request_for(login):\n ... auth = login(json={'username': 'me', 'password': 'mysecret'}).post()\n ... return request.set_headers({'X-AUTH-TOKEN': auth['token']})\n ... return request\n ...\n >>> @api.route('/oauth', ['POST'])\n ... def login(response):\n ... \"\"\"Get an auth token for the given credentials\"\"\"\n ... return response.json()\n ...\n >>> @api.route('/private/resource', ['GET'])\n ... def private_resource(response):\n ... \"\"\"Must be authenticated to access this\"\"\"\n ... return response.json()\n ...\n >>> api.configure(authenticator=authenticator)\n >>> # Now the private resourse will be automatically updated to include auth headers\n >>> private_resource.get()\n\nModels\n------\n\nBasics\n~~~~~~\n\n- Cosmicray ships with a built-in Model class\n- This base class is bound to a specific route handler and defines all the fields that would get mapped to a response or be part as the payload for `post` and `put` requests\n- It automatically uses its defined fields as url parameters and as request body\n- Provides functions to make http calls (ex: `get`, `create`, `update`, `delete`)\n- You can override default behavior, such as create/update paylods\n\n.. code:: python\n\n >>> from cosmicray.model import Model\n >>> class Dog(Model):\n ... __route__ = dogs\n ... __slots__ = [\n ... 'id',\n ... 'name',\n ... 'breed',\n ... 'age'\n ... ]\n >>> manu = Dog(name='Manu', age=4).create()\n >>> manu.breed = 'Husky'\n >>> manu.update()\n >>> manu.delete()\n >>> manu = Dog(id=12345).get()\n >>> alldogs = Dog().get()\n\n\nRelationships with other models/routes\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n\n.. code:: python\n\n >>> from cosmicray.model import relationhip, Model, ModelParam\n >>> class Cat(cosmicray.model.Model):\n ... __route__ = cats\n ... __slots__ = [\n ... 'id',\n ... 'name',\n ... 'age'\n ... ]\n ... friends = relationhip('Friend', urlargs={'id': ModelParam('id')})\n\n\nIf you don't want to use `cosmicray.Model` as your base, you can define your own OR\neven use just use `collections.namedtuple` as the model.\n\n.. code:: python\n\n >>> class MyModel(object):\n ... @classmethod\n ... def _make(cls, response):\n ... obj = cls()\n ... ... do stuff with the response\n ... return obj\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/somerovi/cosmicray", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "cosmicray", "package_url": "https://pypi.org/project/cosmicray/", "platform": "", "project_url": "https://pypi.org/project/cosmicray/", "project_urls": { "Homepage": "https://github.com/somerovi/cosmicray" }, "release_url": "https://pypi.org/project/cosmicray/0.0.13/", "requires_dist": [ "colorama (==0.3.9)", "requests (==2.18.4)", "six (==1.11.0)" ], "requires_python": "", "summary": "Develop a client for your HTTP API and document its quirks and features", "version": "0.0.13" }, "last_serial": 3676978, "releases": { "0.0.10": [ { "comment_text": "", "digests": { "md5": "95b05f431fb5c62c8a5d6e830ad40bf7", "sha256": "d132f7357a7e334c088f82e846f88c58efe7acf17c9b8e0c41b0c436cd0facb0" }, "downloads": -1, "filename": "cosmicray-0.0.10-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "95b05f431fb5c62c8a5d6e830ad40bf7", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 18698, "upload_time": "2018-03-13T14:24:36", "url": "https://files.pythonhosted.org/packages/c7/9e/106d2644fc72c06259a98bebc456153fc15b68af6e744afc202490442d94/cosmicray-0.0.10-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "78a9e96f82c6180646175ed1f917a792", "sha256": "3f570a876bd0371b079aaabc195ad6b92382f4638c37000d464ab8d33e77fca6" }, "downloads": -1, "filename": "cosmicray-0.0.10.tar.gz", "has_sig": false, "md5_digest": "78a9e96f82c6180646175ed1f917a792", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16094, "upload_time": "2018-03-13T14:24:37", "url": "https://files.pythonhosted.org/packages/bb/f6/29d7cb8cd4a7f09acf5bcfef5aa7449f97bf5e707aec03f3841deda99873/cosmicray-0.0.10.tar.gz" } ], "0.0.11": [ { "comment_text": "", "digests": { "md5": "9613b9751855aea8c59ce7e6cf3c4889", "sha256": "4f527b48313b7c9d42874111144648f1d561bf7013264fcca12219745a47c85e" }, "downloads": -1, "filename": "cosmicray-0.0.11-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "9613b9751855aea8c59ce7e6cf3c4889", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 18697, "upload_time": "2018-03-15T14:22:27", "url": "https://files.pythonhosted.org/packages/e8/60/2967b8fc0d0113348f980aee488a3819fd27ccab59a7ffbdb34990f66196/cosmicray-0.0.11-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e085bd16507f7cd92eedec545553ffc2", "sha256": "00d7e2afcc1334d964bbaa761c828e0d1a2f8dc5c55dc02bf15bbd1f98c493bf" }, "downloads": -1, "filename": "cosmicray-0.0.11.tar.gz", "has_sig": false, "md5_digest": "e085bd16507f7cd92eedec545553ffc2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16093, "upload_time": "2018-03-15T14:22:29", "url": "https://files.pythonhosted.org/packages/85/a5/a3aa331f3b9e8e4d1bfca1d2dd394dd804619785ddd5d6135637c7bd0247/cosmicray-0.0.11.tar.gz" } ], "0.0.12": [ { "comment_text": "", "digests": { "md5": "1167c1edbc56567833e37ad7b8237d9d", "sha256": "67a27c1f1bb4a048511b54307ed88bd6208ff06442fb81462ef75a1db203e3de" }, "downloads": -1, "filename": "cosmicray-0.0.12-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "1167c1edbc56567833e37ad7b8237d9d", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 18707, "upload_time": "2018-03-15T14:31:43", "url": "https://files.pythonhosted.org/packages/67/2c/a0dd1adcbf54b5edd973779f6ad2be8a2727b335e3d74d96f7e25657b8ff/cosmicray-0.0.12-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "47fdb9603b06c2bf45f4c010cb318a20", "sha256": "ff69af5f46d856af2bd4db20a2da0e713eeb08525ad0af550b99ee851bce0453" }, "downloads": -1, "filename": "cosmicray-0.0.12.tar.gz", "has_sig": false, "md5_digest": "47fdb9603b06c2bf45f4c010cb318a20", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16099, "upload_time": "2018-03-15T14:31:44", "url": "https://files.pythonhosted.org/packages/87/75/b9aa1547f608810910ac2c5d2520275dddc000566e876d2b2e0d5de52201/cosmicray-0.0.12.tar.gz" } ], "0.0.13": [ { "comment_text": "", "digests": { "md5": "731838caa0c34d7b8efe83270576020f", "sha256": "a919bea78e3f860bec7de332e41ba956dbca7c3d616ba1ac5b883af3fe4d2ed3" }, "downloads": -1, "filename": "cosmicray-0.0.13-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "731838caa0c34d7b8efe83270576020f", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 18724, "upload_time": "2018-03-16T17:10:06", "url": "https://files.pythonhosted.org/packages/4d/43/e45f5f81486c2db77f1a1c83e774767223ebb83bac540cd9ff90186e77c6/cosmicray-0.0.13-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "3d34493a1909cc49757605280f565056", "sha256": "cd3e3952647a45fca2606a39ebeede9037b44c87b01b40de00d8cf7caa15165f" }, "downloads": -1, "filename": "cosmicray-0.0.13.tar.gz", "has_sig": false, "md5_digest": "3d34493a1909cc49757605280f565056", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16109, "upload_time": "2018-03-16T17:10:08", "url": "https://files.pythonhosted.org/packages/00/cc/1d134939507a936c1a1035b31c28968e8d930c70f13ac8b804a906024aee/cosmicray-0.0.13.tar.gz" } ], "0.0.9": [ { "comment_text": "", "digests": { "md5": "f29556c0fae208399e19904428a87976", "sha256": "acb1a9e0e3c0346d68ee193e17b705561061e732bec3856aeff5cb819f768dc6" }, "downloads": -1, "filename": "cosmicray-0.0.9-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "f29556c0fae208399e19904428a87976", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 18660, "upload_time": "2018-01-07T20:04:46", "url": "https://files.pythonhosted.org/packages/b6/a8/18c2314d7744e40de842e36eb729551f71e9bb0d3856583d55b776e81feb/cosmicray-0.0.9-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "fba03233df3d4dbf9f68c9a8c6cf6db2", "sha256": "6ef7524959ec88143b8c5ee6a5232818213e95f950c2dd8d7f3d1882e00e371a" }, "downloads": -1, "filename": "cosmicray-0.0.9.tar.gz", "has_sig": false, "md5_digest": "fba03233df3d4dbf9f68c9a8c6cf6db2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16070, "upload_time": "2018-01-07T20:04:48", "url": "https://files.pythonhosted.org/packages/9e/7f/7bce201c4c676ca4b2f2f7489f938aa41b8671d8d2b3357aab1fba308d9a/cosmicray-0.0.9.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "731838caa0c34d7b8efe83270576020f", "sha256": "a919bea78e3f860bec7de332e41ba956dbca7c3d616ba1ac5b883af3fe4d2ed3" }, "downloads": -1, "filename": "cosmicray-0.0.13-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "731838caa0c34d7b8efe83270576020f", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 18724, "upload_time": "2018-03-16T17:10:06", "url": "https://files.pythonhosted.org/packages/4d/43/e45f5f81486c2db77f1a1c83e774767223ebb83bac540cd9ff90186e77c6/cosmicray-0.0.13-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "3d34493a1909cc49757605280f565056", "sha256": "cd3e3952647a45fca2606a39ebeede9037b44c87b01b40de00d8cf7caa15165f" }, "downloads": -1, "filename": "cosmicray-0.0.13.tar.gz", "has_sig": false, "md5_digest": "3d34493a1909cc49757605280f565056", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16109, "upload_time": "2018-03-16T17:10:08", "url": "https://files.pythonhosted.org/packages/00/cc/1d134939507a936c1a1035b31c28968e8d930c70f13ac8b804a906024aee/cosmicray-0.0.13.tar.gz" } ] }