{ "info": { "author": "MarSal", "author_email": "salermom@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "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": "# Heroku Kafka Easy-E\r\n\r\n**UNOFFICIAL PACKAGE**\r\n\r\nHeroku Kafka is a python package to help you get setup quickly and easily with Kafka on Heroku. There is an [offical package](https://github.com/heroku/kafka-helper) however it has not been does not seem to be maintained anymore. \r\n\r\n\r\n## Install\r\n\r\nThe easiest way to install the package is through pip.\r\n```\r\npip install heroku-kafka-eze\r\npip3 install heroku-kafka-eze\r\n```\r\n\r\n## Usage\r\n\r\nThis package uses the [kafka-python package](https://github.com/dpkp/kafka-python) and the `HerokuKafkaProducer` and `HerokuKafkaConsumer` classes both inherit from the kafka-python base classes, and will contain all the same methods.\r\nIt also uses the [heroku3 package] (https://github.com/martyzz1/heroku3.py) it's a python wrapper for the heroku api. \r\n\r\nNote: You can use this package on locally too. \r\n\r\nNote: To test it is working on local I would simply use heroku CLI with the heroku-kafka plugin or install [heroku-kafka-util](https://github.com/osada9000/heroku-kafka-util) so you can see messages are being sent.\r\n\r\n### Producer\r\n\r\n```python\r\nfrom heroku_kafka_eze import HerokuSSL\r\nfrom heroku_kafka_eze import HerokuKafkaProducer\r\n\r\napp_name = 'your_heroku_app_name'\r\nsecret_key = 'your_heroku_api_key'\r\nheroku_ssl = HerokuSSL(app_name, secret_key)\r\nconfig = heroku_ssl.get_config()\r\n\"\"\"\r\nAll the config variable needed well be received from heroku.\r\n\"\"\"\r\nproducer = HerokuKafkaProducer(\r\n url=config['KAFKA_URL'], # Url string provided by heroku\r\n ssl_cert=config['KAFKA_CLIENT_CERT'], # Client cert string\r\n ssl_key=config['KAFKA_CLIENT_CERT_KEY'], # Client cert key string\r\n ssl_ca=config['KAFKA_TRUSTED_CERT'], # Client trusted cert string\r\n prefix=config['KAFKA_PREFIX'] # Prefix provided by heroku\r\n )\r\n\r\n\"\"\"\r\nThe .send method will automatically prefix your topic with the KAFKA_PREFIX\r\nNOTE: If the message doesn't seem to be sending try `producer.flush()` to force send.\r\n\"\"\"\r\nproducer.send('topic_without_prefix', b\"hola mundo\")\r\n```\r\n\r\nFor all other methods and properties refer to: [KafkaProducer Docs](https://kafka-python.readthedocs.io/en/master/apidoc/KafkaProducer.html).\r\n\r\n\r\n### Consumer\r\n```python\r\nfrom heroku_kafka_eze import HerokuSSL\r\nfrom heroku_kafka_eze import HerokuKafkaConsumer\r\n\r\n\"\"\"\r\nAll the variable names here will be received from Heroku api\r\n*topics are optional and you can pass as many as you want in for the consumer to track,\r\nhowever if you want to subscribe after creation just use .subscribe as shown below.\r\n\r\nNote: The KAFKA_PREFIX will be added on automatically so don't worry about passing it in.\r\n\"\"\"\r\napp_name = 'your_heroku_app_name'\r\nsecret_key = 'your_heroku_api_key'\r\nheroku_ssl = HerokuSSL(app_name, secret_key)\r\nconfig = heroku_ssl.get_config()\r\n\r\nconsumer = HerokuKafkaConsumer(\r\n 'topic_without_prefix', # Optional: You don't need to pass any topic at all\r\n 'topic_without_prefix_2', # You can list as many topics as you want to consume\r\n url=config['KAFKA_URL'], # Url string provided by heroku\r\n ssl_cert=config['KAFKA_CLIENT_CERT'], # Client cert string\r\n ssl_key=config['KAFKA_CLIENT_CERT_KEY'], # Client cert key string\r\n ssl_ca=config['KAFKA_TRUSTED_CERT'], # Client trusted cert string\r\n prefix=config['KAFKA_PREFIX'] # Prefix provided by heroku\r\n )\r\n\"\"\"\r\nTo subscribe to topic(s) after creating a consumer pass in a list of topics without the\r\nKAFKA_PREFIX.\r\n\"\"\"\r\nconsumer.subscribe(topics=('topic_without_prefix'))\r\n\"\"\"\r\n.assign requires a full topic name with prefix\r\n\"\"\"\r\nconsumer.assign([TopicPartition('topic_with_prefix', 2)])\r\n\"\"\"\r\nListening to events it is exactly the same as in kafka_python.\r\nRead the documention linked below for more info!\r\n\"\"\"\r\nfor msg in consumer:\r\n print (msg)\r\n```\r\n\r\nFor all other methods and properties refer to: [KafkaConsumer Docs](https://kafka-python.readthedocs.io/en/master/apidoc/KafkaConsumer.html).\r\n\r\n## Known Issues \r\n- `.assign` does not add in the topic prefix.\r\n- .NamedTemporaryFile may not work properly on a Windows system\r\n\r\n## Contribution\r\nIf you come across any issues feel free to fork and create a PR!\r\n\r\n## Setup\r\nFork the repo, setup virtualenv and pip install\r\n```bash\r\n>>> git clone git@github.com:.git\r\n>>> cd \r\n>>> virtualenv -p python3 venv\r\n>>> source venv/bin/activate\r\n>>> pip install -r requirements.txt\r\n```\r\n\r\nCreate a config.py file with working heroku api key and the name of your app. \r\n```\r\n\r\nAPP_NAME=\"\"\r\nSECRET_KEY=\"\"\r\n\r\nTOPIC1=\"\"\r\nTOPIC2=\"\"\r\n```\r\n\r\n## Tests\r\nPlease make sure that any extra code you write comes with a test, it doesn't need to be over the top but just check what you have written works.\r\nAll tests at the moment require a working kafka setup as its pretty hard to check it is connecting correctly without them.\r\n\r\nTo run the tests:\r\n```bash\r\n>>> python test.py\r\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/masalomon01/heroku-kafka-eze", "keywords": "heroku", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "heroku-kafka-eze", "package_url": "https://pypi.org/project/heroku-kafka-eze/", "platform": "", "project_url": "https://pypi.org/project/heroku-kafka-eze/", "project_urls": { "Homepage": "https://github.com/masalomon01/heroku-kafka-eze" }, "release_url": "https://pypi.org/project/heroku-kafka-eze/0.0.2/", "requires_dist": null, "requires_python": "", "summary": "Python kafka package for use with heroku's kafka. You'll only need your heroku api key and app name", "version": "0.0.2" }, "last_serial": 3609933, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "79f43d9c51a95c3efefcdb4761dd1962", "sha256": "54f5b5d8c20d9007b3631faa805f9870b4019e847c0ef5f79147d73ba94d70eb" }, "downloads": -1, "filename": "heroku-kafka-eze-0.0.1.tar.gz", "has_sig": false, "md5_digest": "79f43d9c51a95c3efefcdb4761dd1962", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4869, "upload_time": "2018-02-23T02:21:21", "url": "https://files.pythonhosted.org/packages/f9/4c/7c53923b8f4c3e6bf5e6ca077b45038d4f73586c19ee4e2b808b38e33c62/heroku-kafka-eze-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "37b2d1b5de5bc884ec123d4ae0983ab0", "sha256": "b211036765e14a26fb45a38dbb23c22d702d2f7b80610bc3c337af599ae55ce6" }, "downloads": -1, "filename": "heroku-kafka-eze-0.0.2.tar.gz", "has_sig": false, "md5_digest": "37b2d1b5de5bc884ec123d4ae0983ab0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4904, "upload_time": "2018-02-23T17:31:47", "url": "https://files.pythonhosted.org/packages/ed/36/2914cb8bd779df2c7696ce2cf6b15d077956d549284f265be605d53ccb32/heroku-kafka-eze-0.0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "37b2d1b5de5bc884ec123d4ae0983ab0", "sha256": "b211036765e14a26fb45a38dbb23c22d702d2f7b80610bc3c337af599ae55ce6" }, "downloads": -1, "filename": "heroku-kafka-eze-0.0.2.tar.gz", "has_sig": false, "md5_digest": "37b2d1b5de5bc884ec123d4ae0983ab0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4904, "upload_time": "2018-02-23T17:31:47", "url": "https://files.pythonhosted.org/packages/ed/36/2914cb8bd779df2c7696ce2cf6b15d077956d549284f265be605d53ccb32/heroku-kafka-eze-0.0.2.tar.gz" } ] }