{ "info": { "author": "jonson", "author_email": "jon@empiricalresults.com", "bugtrack_url": null, "classifiers": [ "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.5" ], "description": "# kclpy\n\nThis is a fork of the [Amazon Kinesis Client Library for Python](https://github.com/awslabs/amazon-kinesis-client-python),\naiming to simplify consuming a kinesis stream using the [Amazon's Kinesis Client Library (KCL)](http://docs.aws.amazon.com/kinesis/latest/dev/developing-consumers-with-kcl.html) multi lang daemon interface.\n\n\n## Why\n\nIt should be easy to consume a kinesis stream in python. This library provides a python API to the KCL.\n\n## Usage\n\nInstall it:\n\n```sh\n> pip install kclpy\n```\n\nImplement a RecordProcessor. See http://docs.aws.amazon.com/kinesis/latest/dev/kinesis-record-processor-implementation-app-py.html for details on the RecordProcessor interface.\n\n```python\nimport kclpy\nimport json\n\nclass MyStreamProcessor(kclpy.RecordProcessor):\n\n def process_record(self, data, partition_key, sequence_number):\n\n try:\n # assumes the incoming kinesis record is json\n data = json.loads(data)\n user = data.get(\"user\")\n \n # explicitly return True to force a checkpoint (otherwise the default)\n # checkpointing strategy is used\n return True\n\n except ValueError:\n # not valid json\n log.error(\"Invalid json placed on queue, nothing we can do\")\n return\n\n\ndef main():\n kclpy.start(MyStreamProcessor())\n\nif __name__ == '__main__':\n main()\n```\n\n## Running\n\nRunning this directly wont do anything other than wait for records via STDIN. The accompanying [Sylvite](https://github.com/empiricalresults/sylvite) library is an executable jar that will launch our record processor and feed it records.\n\nSee the [Sylvite](https://github.com/empiricalresults/sylvite) library for details and a pre-built jar.\n\n```sh\n> java -jar sylvite.jar --config=myapp.properties\n```\n\n## Logging\n\nThis library uses the standard python logging module (all logs under the namespace 'kclpy'). The KCL multi-daemon library expects well formed data on STDOUT, so be sure to configure your logging to use STDERR or a file. Do not use print statements in your processor!\n\n\n## Background\n\nThe key concept to understand when using the KCL's multi-lang daemon is that there is a Java process doing all communication with the kinesis API and a language agnostic child process that reads and writes from STDIN/STDOUT. This is very similar to how Hadoop streaming works. In order to consume the stream, we need to start up a Java process, which will in-turn start up a child process that will actually handle consuming the stream data.\n\nWhile this sounds complicated, building on the KCL gives us the advantage of all the checkpointing, resharding and monitoring work that is baked into the KCL. The KCL is also maintained by the awslabs team, so any future enhancements will be handled for free.\n\n\n## RecordProcessor\n\nkclpy is based on awslabs' sample code, with only a few minor tweaks in logging and checkpointing.\n\n### API\n\nRefer to [Amazon's documentation](http://docs.aws.amazon.com/kinesis/latest/dev/kinesis-record-processor-implementation-app-py.html), this fork maintains compatibility with the original implementation.\n\n\n### Checkpointing\n\nThe KCL uses a DynamoDB table to maintain it's current position in the stream (checkpoint). kclpy allows you to customize the checkpointing behaviour. The following kwargs can be passed to kclpy.RecordProcessor:\n\n* checkpoint_freq_seconds - Checkpoint at a fixed interval (in seconds).\n* records_per_checkpoint - Checkpoint at a fixed number of records processed.\n\n```python\ndef main():\n # automatically checkpoint every 60 seconds\n every_minute_processor = MyStreamProcessor(checkpoint_freq_seconds=60)\n \n # or checkpoint every 100 records\n every_hundred_records_processor = MyStreamProcessor(records_per_checkpoint=100)\n \n #todo: start the processor\n```\n\nAlternatively, you can force an explict checkpoint by returning True in your *process_record* call. But be warned, doing this every record will result in a lot of writes to your DynamoDB table.\n\n```python\nimport kclpy\n\ndef process_data(data):\n # if this is a special record, tell the library to checkpoint so we don't process\n # it again.\n return True\n\nclass MyStreamProcessor(kclpy.RecordProcessor):\n\n def process_record(self, data, partition_key, sequence_number):\n should_checkpoint = process_data(data)\n return should_checkpoint\n \ndef main():\n # checkpoints will only be made if process_record() returns True\n # probably not a great idea in the general case\n manual_checkpointer = MyStreamProcessor(\n checkpoint_freq_seconds=0, \n records_per_checkpoint=0\n ) \n \n #todo: start the processor\n```\n\n", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/empiricalresults/kclpy/archive/0.1.2.tar.gz", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/empiricalresults/kclpy", "keywords": "amazon,kinesis,kinesis-client-library,client-library,library", "license": "Amazon Software License", "maintainer": null, "maintainer_email": null, "name": "kclpy", "package_url": "https://pypi.org/project/kclpy/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/kclpy/", "project_urls": { "Download": "https://github.com/empiricalresults/kclpy/archive/0.1.2.tar.gz", "Homepage": "https://github.com/empiricalresults/kclpy" }, "release_url": "https://pypi.org/project/kclpy/0.2.0/", "requires_dist": null, "requires_python": null, "summary": "A python interface for the Amazon Kinesis Client Library MultiLangDaemon", "version": "0.2.0" }, "last_serial": 2133819, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "6d2f110322ff3d5c59f8c9c176228b40", "sha256": "421109eff8b4c758e58994078d1e10255e1427eba26568980e1c8c8eaff135f4" }, "downloads": -1, "filename": "kclpy-0.1.0.tar.gz", "has_sig": false, "md5_digest": "6d2f110322ff3d5c59f8c9c176228b40", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8459, "upload_time": "2015-10-12T20:27:03", "url": "https://files.pythonhosted.org/packages/cb/2f/a9cf95dacd96ec8b0568dc1500b4757fcc97653aee2e5ae9fdd0c65e07e5/kclpy-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "abed5e27d04e57a29d46461415722d57", "sha256": "51424354c8e1911356ac92d055129b2f4e5623b8db9618059f7101bc92ec7d2e" }, "downloads": -1, "filename": "kclpy-0.1.1.tar.gz", "has_sig": false, "md5_digest": "abed5e27d04e57a29d46461415722d57", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10127, "upload_time": "2015-11-10T00:37:54", "url": "https://files.pythonhosted.org/packages/3f/00/18ea4075be9f9b43ff061b3275f9fc2a8bc478b9844f12c3a07c6a2cabc2/kclpy-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "0c09256e1177f95dcaf249405cc70990", "sha256": "584cf66a7e75caf5795f758afd5fa23747eb3eca8eb70ebef30c96f565a69b1d" }, "downloads": -1, "filename": "kclpy-0.1.2.tar.gz", "has_sig": false, "md5_digest": "0c09256e1177f95dcaf249405cc70990", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10140, "upload_time": "2015-11-20T09:26:54", "url": "https://files.pythonhosted.org/packages/2e/45/ee093b73a942866e2e71cf4e32c8845c650f60e26d6acfb6b8fc8d49f362/kclpy-0.1.2.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "9fc212230140f4d0193dc707c9caf7e9", "sha256": "0cbc30bf2865bbeef62ca98b23e467d4c3ef2c7814ebec0c67d242f3a2198372" }, "downloads": -1, "filename": "kclpy-0.2.0.tar.gz", "has_sig": false, "md5_digest": "9fc212230140f4d0193dc707c9caf7e9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10214, "upload_time": "2016-05-25T22:03:58", "url": "https://files.pythonhosted.org/packages/3f/19/687917d4e8c097163767318849f17e215a45277f18c847f799b7cfb59858/kclpy-0.2.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "9fc212230140f4d0193dc707c9caf7e9", "sha256": "0cbc30bf2865bbeef62ca98b23e467d4c3ef2c7814ebec0c67d242f3a2198372" }, "downloads": -1, "filename": "kclpy-0.2.0.tar.gz", "has_sig": false, "md5_digest": "9fc212230140f4d0193dc707c9caf7e9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10214, "upload_time": "2016-05-25T22:03:58", "url": "https://files.pythonhosted.org/packages/3f/19/687917d4e8c097163767318849f17e215a45277f18c847f799b7cfb59858/kclpy-0.2.0.tar.gz" } ] }