{ "info": { "author": "Jeffrey Starker", "author_email": "jstarker@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Framework :: Flask", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Programming Language :: Python :: 2.7", "Topic :: Internet :: WWW/HTTP", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "# Flask Avro\nThis is a simple AVRO IPC endpoint registration extension for Flask.\n\nFor information about AVRO checkout:\n\n* [https://avro.apache.org/](https://avro.apache.org/)\n* [http://avro.apache.org/docs/current/spec.html](http://avro.apache.org/docs/current/spec.html)\n\n# Usage\nThis extension allows you to register a AVRO protocol to a specific URL route. This allows you to handle the messages defined in the protocol.\n\nGiven a AVRO protocol `test.avpr`:\n\n```\n{\n \"namespace\": \"org.avro\",\n \"protocol\": \"Test\",\n\n \"types\": [\n {\n \"name\": \"Message\",\n \"type\": \"record\",\n \"fields\": [\n {\n \"name\": \"from\",\n \"type\": \"string\"\n },\n {\n \"name\": \"body\",\n \"type\": \"string\"\n }\n ]\n }\n ],\n\n \"messages\": {\n \"echo_message\": {\n \"request\": [\n {\n \"name\":\"message\",\n \"type\":\"Message\"\n }\n ],\n \"response\": \"string\",\n \"errors\": []\n }\n }\n}\n```\n\nAn example of a simple Flask app that implements logic for the message `echo_message`, you could do the following:\n\n```\nfrom flask import Flask\nfrom flask.ext.avro import FlaskAvroEndpoint\n\ntest_avro_endpoint = FlaskAvroEndpoint.from_filename(\"test\", \"test.avpr\")\n\n@test_avro_endpoint.register(\"echo_message\"):\ndef handle_test_send(request_message):\n\n return request_message.get(\"body\")\n\n\napp = Flask(__name__)\n\ntest_avro_endpoint.connect(app, \"/\")\n \n```\n\nThe above code registers a function that will handle the request message when the endpoint receives a message for `echo_message`. The function is responsible for also returning the correct object that is required as response of the protocol.\n\nIn order to interact with endpoint, the client would use the AVRO IPC `Requestor` API for your specific language.\n\nFor Python, you'll have to install the `avro` package with pip and then your client could look like this:\n\n```\nfrom avro.protocol import protocol\nfrom avro.ipc import Requestor, HTTPTransceiver\n\n\nTEST_PROTOCOL = protocol.parse(open(\"test.avpr\").read()) \nclient = HTTPTransceiver(\"localhost\", 9090)\nrequestor = Requestor(TEST_PROTOCOL, client)\n\ntest_message = {\n \"from\": \"Ground Control\",\n \"body\": \"Take your protein pills and put your helmet on\"\n}\n\n\nresponse = requestor.request(\"echo_message\", test_message)\n\nclient.close()\n```\n\n# Test Helpers\n\nThis module also includes a test helper to test your Avro endpoints. Normally, when you test your views, you'll want to use the `test_flask_app.test_client()` to generate requests to your view endpoints. However, creating AVRO request messages is a little cumbersome.\n\nTo help facilitate testing, there is a test utility class `flask.ext.avro.util.FlaskAvroTestClient`. This is a convenience wrapper around the test_client.\n\nExample usage:\n\n```\nfrom unittest import TestCase\nfrom flask.ext.avro.util import FlaskAvroTestClient\n\nfrom avro.protocol import protocol\n\nTEST_PROTOCOL = protocol.parse(open(\"test.avpr\").read()) \n\nclass TestAvroEndpoint(TestCase):\n\n def setUp(self):\n # Generate your test app or pull a created one\n ...\n self.app = test_app\n \n def test_endpoint(self):\n \n client = FlaskAvroTestClient(TEST_PROTOCOL, self.app.test_client(), \"/\")\n \n test_body = \"Take your protein pills and put your helmet on\"\n test_message = test_message = {\n \"from\": \"Ground Control\",\n \"body\": test_body\n }\n \n response = client.request(\"echo_message\", test_message)\n \n self.assertEqual(test_body, response)\n\n```\n\n-------------------------------------------------------------------------------\n0.0.1\n-------------------------------------------------------------------------------\n- Initial public version.\n-------------------------------------------------------------------------------", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/packagelib/flask-avro", "keywords": "flask avro", "license": "Apache License (2.0)", "maintainer": "", "maintainer_email": "", "name": "flask-avro", "package_url": "https://pypi.org/project/flask-avro/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/flask-avro/", "project_urls": { "Homepage": "https://github.com/packagelib/flask-avro" }, "release_url": "https://pypi.org/project/flask-avro/0.0.1/", "requires_dist": null, "requires_python": "", "summary": "Simple AVRO IPC endpoint registration for Flask", "version": "0.0.1" }, "last_serial": 2227361, "releases": { "0.0.0": [], "0.0.1": [ { "comment_text": "", "digests": { "md5": "3fa0a646475d073db120b5b68f0f349c", "sha256": "25db22263639f1c9092a7f96b63a3fee2651160910232f81bc4e531528aacf0c" }, "downloads": -1, "filename": "flask-avro-0.0.1.tar.gz", "has_sig": false, "md5_digest": "3fa0a646475d073db120b5b68f0f349c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5353, "upload_time": "2016-07-17T22:26:23", "url": "https://files.pythonhosted.org/packages/d7/fe/49f85fb3ca382761d53ad5d93a80acaaa794e040d19ff7a02bc346814d78/flask-avro-0.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "3fa0a646475d073db120b5b68f0f349c", "sha256": "25db22263639f1c9092a7f96b63a3fee2651160910232f81bc4e531528aacf0c" }, "downloads": -1, "filename": "flask-avro-0.0.1.tar.gz", "has_sig": false, "md5_digest": "3fa0a646475d073db120b5b68f0f349c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5353, "upload_time": "2016-07-17T22:26:23", "url": "https://files.pythonhosted.org/packages/d7/fe/49f85fb3ca382761d53ad5d93a80acaaa794e040d19ff7a02bc346814d78/flask-avro-0.0.1.tar.gz" } ] }