{ "info": { "author": "Marcel Neidinger", "author_email": "mneiding@cisco.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 2 - Pre-Alpha", "Intended Audience :: Developers", "Natural Language :: English", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "# PyAdaptiveCards\n\n*Author adaptive cards in pure python*\n\n[![PyPi](https://img.shields.io/pypi/v/pyadaptivecards.svg)](https://pypi.python.org/pypi/pyadaptivecards)\n[![ReadTheDocs](https://readthedocs.org/projects/pyadaptivecards/badge/?version=latest)](https://pyadaptivecards.readthedocs.io/en/latest/?badge=latest)\n[![PyUp](https://pyup.io/repos/github/CiscoSE/pyadaptivecards/shield.svg)](https://pyup.io/repos/github/CiscoSE/pyadaptivecards/)\n\n\n---\n\n## Introduction \n\n[Adaptive Cards](https://adaptivecards.io/) are a great way to extend your bot interactions. However, writing the JSON required to specify the card layout by hand can be cumbersome and error prone. And while using a [designer](https://adaptivecards.io/designer/) is a good way to manually create cards this does not cover cards that are generated by code. PyAdaptiveCards allows you to author cards in native python without ever touching the underlying json. \n\nA code sample says more then a thousand words so the following code snippet ...\n\n```python\nfrom pyadaptivecards.card import AdaptiveCard\nfrom pyadaptivecards.inputs import Text, Number\nfrom pyadaptivecards.components import TextBlock\nfrom pyadaptivecards.actions import Submit\n\ngreeting = TextBlock(\"Hey hello there! I am a adaptive card\")\nfirst_name = Text('first_name', placeholder=\"First Name\")\nage = Number('age', placeholder=\"Age\")\n\nsubmit = Submit(title=\"Send me!\")\n\ncard = AdaptiveCard(body=[greeting, first_name, age], actions=[submit])\ncard_json = card.to_json(pretty=True)\nprint(card_json)\n```\n\n... produces this json ...\n\n```json\n{\n \"$schema\": \"http://adaptivecards.io/schemas/adaptive-card.json\",\n \"actions\": [\n {\n \"title\": \"Send me!\",\n \"type\": \"Action.Submit\"\n }\n ],\n \"body\": [\n {\n \"text\": \"Hey hello there! I am a adaptive card\",\n \"type\": \"TextBlock\"\n },\n {\n \"id\": \"first_name\",\n \"placeholder\": \"First name\",\n \"type\": \"Input.Text\"\n },\n {\n \"id\": \"age\",\n \"placeholder\": \"Age\",\n \"type\": \"Input.Number\"\n }\n ],\n \"type\": \"AdaptiveCard\",\n \"version\": \"1.1\"\n}\n```\n\n... which looks like this in [Webex Teams](https://teams.webex.com) ...\n\n![screenshot of card in webex teams](cards_sample.png)\n\n## Usage with Webex Teams\n\nBelow is an example how to use pyadaptivecards with Webex Teams. \n\n### Using raw requests \n\n```python\nimport requests \nimport json\n\nfrom pyadaptivecards.card import AdaptiveCard\nfrom pyadaptivecards.inputs import Text, Number\nfrom pyadaptivecards.components import TextBlock\nfrom pyadaptivecards.actions import Submit\n\nauth_token = \"\"\nheaders = {\n \"Authorization\": \"Bearer \" + auth_token\n}\n\n# Create card\ngreeting = TextBlock(\"Hey hello there! I am a adaptive card\")\nfirst_name = Text('first_name', placeholder=\"First Name\")\nage = Number('age', placeholder=\"Age\")\n\nsubmit = Submit(title=\"Send me!\")\n\ncard = AdaptiveCard(body=[greeting, first_name, age], actions=[submit])\n\n# Create attachment\nattachment = {\n \"contentType\": \"application/vnd.microsoft.card.adaptive\",\n \"content\": card.to_dict()\n}\n\n# Create payload for the webrequest\npayload = {\n \"roomId\": \"\",\n \"attachments\" : [attachment],\n \"text\": \"Fallback Text\"\n}\n\nresponse = requests.post(\"https://api.ciscospark.com/v1/messages\", headers=headers, data=payload)\n```\n\n### Using the webexteamssdk\nThe [webexteamssdk](https://github.com/CiscoDevNet/webexteamssdk) provides a great wrapper around the Webex Teams API that can be used to interact with the API in native python. The following example shows how to use pyadaptivecards with the newly implemented attachments option. \n\n```python\nfrom pyadaptivecards.card import AdaptiveCard\nfrom pyadaptivecards.inputs import Text, Number\nfrom pyadaptivecards.components import TextBlock\nfrom pyadaptivecards.actions import Submit\n\nfrom webexteamssdk import WebexTeamsAPI\n\ngreeting = TextBlock(\"Hey hello there! I am a adaptive card\")\nfirst_name = Text('first_name', placeholder=\"First Name\")\nage = Number('age', placeholder=\"Age\")\n\nsubmit = Submit(title=\"Send me!\")\n\ncard = AdaptiveCard(body=[greeting, first_name, age], actions=[submit])\n\n# Create a webex teams api connection\napi = WebexTeamsAPI()\nroom_id = \"\"\n# Create a dict that will contain the card as well as some meta information\nattachment = {\n \"contentType\": \"application/vnd.microsoft.card.adaptive\",\n \"content\": card.to_dict(),\n}\napi.messages.create(roomId=room_id, text=\"Fallback\", attachments=[attachment])\n```\n\n## Features\n\n- Supports all components, options and features of adaptive cards version 1.1\n- Create adaptive cards from pure python\n\n## Installation\n\nYou can install PyAdaptiveCards using pip by issuing\n\n```bash\n$ pip install pyadaptivecards\n```\n\nFor more information on how to use this package please check the project documentation at https://pyadaptivecards.readthedocs.io.\n\n## Authors & Maintainers\n\n- Marcel Neidinger \n\n## Credits\n\nThe following resources were influential in the creation of this project:\n\n- This package was created with [Cookiecutter](https://github.com/audreyr/cookiecutter) and a derivative of the[audreyr/cookiecutter-pypackage](https://github.com/audreyr/cookiecutter-pypackage) project template.\n\n## License\n\nThis project is licensed to you under the terms of the [Cisco SampleCode License](./LICENSE).", "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/CiscoSE/pyadaptivecards", "keywords": "pyadaptivecards", "license": "Cisco Sample Code License, Version 1.1", "maintainer": "", "maintainer_email": "", "name": "pyadaptivecards", "package_url": "https://pypi.org/project/pyadaptivecards/", "platform": "", "project_url": "https://pypi.org/project/pyadaptivecards/", "project_urls": { "Homepage": "https://github.com/CiscoSE/pyadaptivecards" }, "release_url": "https://pypi.org/project/pyadaptivecards/0.1.1/", "requires_dist": null, "requires_python": "", "summary": "Author adaptive cards in pure python", "version": "0.1.1", "yanked": false, "yanked_reason": null }, "last_serial": 8307109, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "3f8f5555b2cf1258c8dfb9dc9e6ec668", "sha256": "13fd487de9394600c2f0624aca32660c4fc977e2dcd815ca4edadda3ba4b35f6" }, "downloads": -1, "filename": "pyadaptivecards-0.1.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "3f8f5555b2cf1258c8dfb9dc9e6ec668", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 18992, "upload_time": "2019-10-30T18:37:49", "upload_time_iso_8601": "2019-10-30T18:37:49.047924Z", "url": "https://files.pythonhosted.org/packages/a2/3b/183bdf98621f3168775465c12e06955d1f9fcdb285300a0f1feb3d75c761/pyadaptivecards-0.1.0-py2.py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "78137aa5801970b744c973f08dd088c3", "sha256": "b19957ba9abe484f9c377f8ab348fde781b8f1185cb56ce5a24baa3afa67f035" }, "downloads": -1, "filename": "pyadaptivecards-0.1.0.tar.gz", "has_sig": false, "md5_digest": "78137aa5801970b744c973f08dd088c3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16923, "upload_time": "2019-10-30T18:37:51", "upload_time_iso_8601": "2019-10-30T18:37:51.702777Z", "url": "https://files.pythonhosted.org/packages/c0/dd/fcdcf95c47f9d2a07df7b5821543472a6ced3695799925d5ee3241ddd7e6/pyadaptivecards-0.1.0.tar.gz", "yanked": false, "yanked_reason": null } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "3f1ddee9ec8b13063a2b79986732b441", "sha256": "0f3bd37415b891b0e3b0849e9023d8a537c5c9a7597f2b1817bf9780449e7279" }, "downloads": -1, "filename": "pyadaptivecards-0.1.1.tar.gz", "has_sig": false, "md5_digest": "3f1ddee9ec8b13063a2b79986732b441", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 59924, "upload_time": "2020-09-30T13:39:41", "upload_time_iso_8601": "2020-09-30T13:39:41.291213Z", "url": "https://files.pythonhosted.org/packages/82/cc/68c4cd9beb53a8222c2d1728871e393dc4a037516d4c2bf3df88034d8ef0/pyadaptivecards-0.1.1.tar.gz", "yanked": false, "yanked_reason": null } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "3f1ddee9ec8b13063a2b79986732b441", "sha256": "0f3bd37415b891b0e3b0849e9023d8a537c5c9a7597f2b1817bf9780449e7279" }, "downloads": -1, "filename": "pyadaptivecards-0.1.1.tar.gz", "has_sig": false, "md5_digest": "3f1ddee9ec8b13063a2b79986732b441", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 59924, "upload_time": "2020-09-30T13:39:41", "upload_time_iso_8601": "2020-09-30T13:39:41.291213Z", "url": "https://files.pythonhosted.org/packages/82/cc/68c4cd9beb53a8222c2d1728871e393dc4a037516d4c2bf3df88034d8ef0/pyadaptivecards-0.1.1.tar.gz", "yanked": false, "yanked_reason": null } ], "vulnerabilities": [] }