Skip to main content

Python Card Framework

This is a library designed to allow Python developers to treat the Chat API JSON to be generated for cards and dialogs as objects, each capable of rendering themselves into valid JSON instead of hand-crafting or cut-and-pasting JSON in large blocks.

The exact JSON that is being rendered can be found in the official Google Developer Docs pages here: https://developers.google.com/chat/api/reference/rest/v1/spaces.messages?hl=en

Intention

In order to generate or send messages from a chat application to the user, the messages must be formed of valid JSON objects. In the event that the message is malformed, a simple 'Chat App not responding' message is returned. This leads to the developer having to insert large blocks of JSON in their Python code, much of which is boiler-plate and can easily lead to hard to find cut and paste errors.

As a result this library of objects has been created to alleviate the problem. The developer can now create and manipulate first-class Python objects which know how to correctly render themselves. Thus, instead of inserting this:

  return {
    "sections": [
        {
          "widgets": [
            {
              "decoratedText": {
                "topLabel": "Hello, my name is Inigo Montoya",
                "text": "You killed my father. Prepare to die.",
                "startIcon": {
                  "knownIcon": "PERSON"
                }
              }
            }
        ]
      }
    ],
    "header": {
      "title": "The Princess Bride",
      "imageUrl": "https://source.unsplash.com/featured/320x180?nature&sig=8",
      "imageType": "CIRCLE"
    }
  }

... the developer can instead do this (with the appropriate imports, of course):

from card_framework.v2 import Card, CardHeader, Message, Section
from card_framework.v2.widgets import DecoratedText, Icon
text = DecoratedText(top_label='Hello, my name is Inigo Montoya',
                     text='You killed my father. Prepare to die.',
                     start_icon=Icon(known_icon=Icon.KnownIcon.PERSON))
widgets = [text]
header = CardHeader(title='The Princess Bride',
                    image_url='https://source.unsplash.com/featured320x180?nature&sig=8')
card = Card(header=header, sections=[Section(widgets=widgets)])

return Message(cards=[card]).render()

which will return the correct JSON.

Metadata

Release files for python-card-framework 2.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-card-framework 2.4.0
File Size Uploaded
python_card_framework-2.4.0.tar.gz 30.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-card-framework 2.4.0
File Interpreter ABI Platform
python_card_framework-2.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 100.6 kB

Release files / python_card_framework-2.4.0.tar.gz

Download URL python_card_framework-2.4.0.tar.gz
Size 30.4 kB
Tags Source
SHA-256 checksum
How to use checksums
d8cd6bb8a7198d825ace4c0327473fd876dd364954184c985719463848f4c09e
BLAKE2b-256 checksum
How to use checksums
991690364ab2fc054fabc7004cea5e1fea3edd36f3a78a3578bceffd0626cc0e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.11

Release files / python_card_framework-2.4.0-py3-none-any.whl

Download URL python_card_framework-2.4.0-py3-none-any.whl
Size 70.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4d848356814b46cdcfaf65872e9783bafb1ce26197020df2d8ac53612a03d8f6
BLAKE2b-256 checksum
How to use checksums
cb146b7c79442aff9125bb43a7fccd86d3072986ae34c39145a0a44bd44cc084
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.11

Release history Release notifications | RSS feed

This release

2.4.0 This release

2 release files

2.3.0

2 release files

2.2.6

2 release files

2.2.5

2 release files

2.2.4

2 release files

2.2.3

2 release files

2.2.2

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.1.1

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

1 release file

0.7.0

1 release file

0.6.2

1 release file

0.6.1

1 release file

0.6.0

1 release file

0.5.1

1 release file

0.5.0

1 release file

0.4.2

1 release file

0.4.1

1 release file

0.4.0

1 release file

0.2.0

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page