{ "info": { "author": "Soluto", "author_email": "it@soluto.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "Shisell is a service agnostic abstraction for analytic dispatchers.\n\nIt helps you dispatch analytic events which are scoped to a component or module. It allows providing extra data (properties), identities, and metadata to the dispatched events. Shisell's analytic dispatchers are immutable and can be composed by passing a dispatcher object to a child module. Shisell can be used as an abstraction for sending analytic events so you can easily switch or add analytic services without rewriting the event dispatching code.\n\n## Install\n\n```sh\n$ pip install shisell\n```\n\n## Usage\n\nAt the initialization code of your app, you should create a root dispatcher object. This root dispatcher is the \"parent\" of all dispatchers, and it is where you would set up common properties which needs to be attached to all the dispatched events. \nIn order to create the root dispatcher, shisell needs to receive a writer function. The writer function is just a function that accepts an object of type [AnalyticsEventModel](https://github.com/soluto-private/shisell-python/blob/master/shisell/analytics_event_model.py), and usually writes it to an analytics service (e.g. Mixpanel, Google Analytics etc.). \nOut of the box Shisell comes with a writer function which outputs the event to the logger.\n\nUse the following code to use the built in dispatcher: \n\n```python\nfrom shisell import create_root_dispatcher\nfrom shisell.writers import log_writer\n\nroot_dispatcher = create_root_dispatcher(log_writer)\n```\n\nOnce the root dispatcher is created you can compose dispatchers by extending with one of the extender methods. Finally, call dispatch on one of the dispatchers with an event name.\n\n```python\nfrom shisell.extenders import create_scoped, with_extra, with_identity\n# Composing dispatchers\nlogin_view_dispatcher = root_dispatcher.extend(create_scoped('LoginView'))\nregistration_box_dispatcher = login_view_dispatcher.extend(with_extra('type', 'registration'))\n# ...\nregistration_box_dispatcher.extend(with_identity('email', user_email), with_extra('btn','register')).dispatch('click')\n\n# logger output:\n# { \n# \"Scope\":\"LoginView\",\n# \"Name\":\"click\",\n# \"MetaData\":{},\n# \"ExtraData\":{ \n# \"type\":\"registration\",\n# \"btn\":\"register\"\n# },\n# \"Identities\":{ \n# \"email\":\"shisell@soluto.com\"\n# }\n# }\n```\n\n#### Using Filters\n\nFilters are functions which are executed by the root dispatcher when dispatching events. Filters can be used to add dynamic values to the dispatched event. \nHere's an example adding a Timestamp propery:\n\n```python\ndef add_timestamp(model):\n model.ExtraData[\"timestamp\"] = time.time()\n\nroot_dispatcher = create_root_dispatcher(log_writer).extend(with_filter(add_timestamp))\n\nhome_page_dispatcher = root_dispatcher.extend(create_scoped('HomePage'))\n# ...\nhome_page_dispatcher.dispatch('PageView')\n\n# console output:\n# { \n# \"Scope\":\"HomePage\",\n# \"Name\":\"PageView\",\n# \"MetaData\":{ \n#\n# },\n# \"ExtraData\":{ \n# \"timestamp\":1537108727.4074192\n# },\n# \"Identities\":{ \n#\n# }\n# }\n```\n\n#### Extending the Dispatcher\nWe use several different extension methods for composing dispatchers, and you can easily add a custom one. For example, let's say that we frequently create dispatchers with several extra data properties that are part of our user model. So we have this sort of code often:\n\n```python\nhome_view_dispatcher = root_dispatcher.extend(\n with_extra('firstName', user.first_name),\n with_extra('lastName', user.last_name),\n with_extra('email', user.email),\n with_extra('age', user.age),\n);\n```\n\nInstead of writing this code every time you can add a method that does this for you:\n\n```python\ndef with_user(user):\n new_context = AnalyticsContext()\n new_context.ExtraData['firstName'] = user.first_name\n new_context.ExtraData['lastName'] = user.last_name\n new_context.ExtraData['email'] = user.email\n new_context.ExtraData['age'] = user.age\n \n return with_context(new_context)\n\n# Usage\nhome_view_dispatcher = root_dispatcher.extend(with_user(user))\n```\n\n#### Creating a Custom Root Dispatcher\nWhen you call 'dispatch' on a dispatcher, it creates a union of the [AnalyticsContext](https://github.com/soluto-private/shisell-python/blob/master/shisell/analytics_context.py) of each dispatcher along the way until reaching the root dispatcher. The default root dispatcher that is generated by calling `create_root_dispatcher` simply converts the unified context to an AnalyticsEventModel and passes it on to the writer function.\n\nIf you would like to use a different model than the AnalyticsEventModel you can create your own custom dispatcher by creating a new [AnalyticsDispatcher](https://github.com/soluto-private/shisell-python/blob/master/shisell/analytics_dispatcher.py) and passing it a function that receives two parameters - the eventName and the context.\n\nNote: it is the root dispatcher's responsibility to run the filters.\n\n## Contributing\nThanks for thinking about contributing! We are looking for contributions of any sort and size - features, bug fixes, documentation or anything else that you think will make shisell better.\n* Fork and clone locally\n* Create a topic specific branch\n* Add a cool feature or fix a bug\n* Add tests\n* Send a Pull Request\n\n#### Running Tests\n```sh\n$ python3 -m unittest\n```\n\nRunning with coverage:\n```sh\n$ coverage run --source=shisell -m unittest\n$ coverage report -m\n```", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/Soluto/shisell-python", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "shisell", "package_url": "https://pypi.org/project/shisell/", "platform": "", "project_url": "https://pypi.org/project/shisell/", "project_urls": { "Homepage": "https://github.com/Soluto/shisell-python" }, "release_url": "https://pypi.org/project/shisell/1.0.0/", "requires_dist": null, "requires_python": "", "summary": "Shisell is a service agnostic abstraction for analytic dispatchers.", "version": "1.0.0" }, "last_serial": 4315857, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "781687ed498bd2b8e1fa8c31d33fdb4c", "sha256": "8a94d8c9063dd0acdf8eccb7fd6ac6dab0e41bbf7a10490c310622166f4bb938" }, "downloads": -1, "filename": "shisell-1.0.0.tar.gz", "has_sig": false, "md5_digest": "781687ed498bd2b8e1fa8c31d33fdb4c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5108, "upload_time": "2018-09-27T11:15:01", "url": "https://files.pythonhosted.org/packages/d8/b7/b1816a7eb38f479e87a08b94ca0438754824b8855bc32bc9974ce54c9daa/shisell-1.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "781687ed498bd2b8e1fa8c31d33fdb4c", "sha256": "8a94d8c9063dd0acdf8eccb7fd6ac6dab0e41bbf7a10490c310622166f4bb938" }, "downloads": -1, "filename": "shisell-1.0.0.tar.gz", "has_sig": false, "md5_digest": "781687ed498bd2b8e1fa8c31d33fdb4c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5108, "upload_time": "2018-09-27T11:15:01", "url": "https://files.pythonhosted.org/packages/d8/b7/b1816a7eb38f479e87a08b94ca0438754824b8855bc32bc9974ce54c9daa/shisell-1.0.0.tar.gz" } ] }