Skip to main content

PyCloudEvents

This Python library defines a CloudEvent class that represents a CloudEvent object according to the CloudEvents specification.

TOC

Installation

pip install pycloudevents

Usage

The CloudEvent class provides methods to create, serialize (convert to JSON), and deserialize CloudEvents.

Creating a CloudEvent object

There are four ways to create a CloudEvent object:

Using keyword arguments in the constructor:

from pycloudevents import CloudEvent

event = CloudEvent(
    id="my-id",
    source="https://example.com/source",
    type="com.cloudevents.example.extension",
    data={"message": "Hello, world!"},
)

From a dictionary:

from pycloudevents import CloudEvent

data = {
    "id": "12345",
    "specversion": "1.0",
    "type": "com.cloudevents.example.extension",
    "source": "https://example.com/source",
    "data": {"message": "Hello, world!"},
}

event = CloudEvent.from_dict(data)

From a mapping object:

from pycloudevents import CloudEvent

data = {
    "id": "12345",
    "specversion": "1.0",
    "type": "com.cloudevents.example.extension",
    "source": "https://example.com/source",
    "data": {"message": "Hello, world!"},
}

event = CloudEvent.from_mapping(data)

From a JSON string:

from pycloudevents import CloudEvent

json_string = '{"id": "12345", "specversion": "1.0", "type": "com.cloudevents.example.extension", "source": "https://example.com/source", "data": {"message": "Hello, world!"}}'

event = CloudEvent.from_json(json_string)

Serializing a CloudEvent object to JSON

The to_structured method converts a CloudEvent object to a JSON string:

from pycloudevents import CloudEvent

event = CloudEvent(...)  # Create an event object

json_data = event.to_structured()
print(json_data)

Deserializing a JSON string to a CloudEvent object

The from_json class method creates a CloudEvent object from a JSON string:

from pycloudevents import CloudEvent

json_string = '{"specversion": "1.0", ...}'  # Your JSON string

event = CloudEvent.from_json(json_string)

CloudEvent Attributes

The CloudEvent class includes the following attributes according to the CloudEvents specification:

  • id: (str) The identifier of the event.
  • source: (str) The source of the event.
  • specversion: (str) The CloudEvents specification version (default is "1.0").
  • type: (str) The type of the event.
  • datacontenttype: (Optional[str]) The data content type (default is None).
  • dataschema: (Optional[str]) The data schema (default is None).
  • subject: (Optional[str]) The subject of the event (default is None).
  • time: (Optional[str]) The timestamp of the event (default is None).
  • data: (Any) The data associated with the event (default is None).
  • extensions: (Hashable) Additional extensions for the event.

Contributing

See more in our Contributing Guidelines

Metadata

Release files for pycloudevents 0.1.4

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

Source distribution (sdist)

Source distribution for pycloudevents 0.1.4
File Size Uploaded
pycloudevents-0.1.4.tar.gz 8.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pycloudevents 0.1.4
File Interpreter ABI Platform
pycloudevents-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 16.7 kB

Release files / pycloudevents-0.1.4.tar.gz

Download URL pycloudevents-0.1.4.tar.gz
Size 8.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e1ee031e9ec8c4ee81bd2c4bf677021a625529f79c10ccab0a0de17cca8b089b
BLAKE2b-256 checksum
How to use checksums
95b72f0ea8685ad1303842bf830852a8cff2b59887f268569bb649be3f0e0cbb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via pdm/2.14.0 CPython/3.10.12 Linux/6.5.0-1017-azure

Release files / pycloudevents-0.1.4-py3-none-any.whl

Download URL pycloudevents-0.1.4-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
97a62222f3a2e6456b9e71bb185de8fffd8fc4bb0118892326ae293c3e07f0ca
BLAKE2b-256 checksum
How to use checksums
e536d232f0d99ba03ece8cdc4359e8dcd342519eac5bf32a317bd218a4ca7cd6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via pdm/2.14.0 CPython/3.10.12 Linux/6.5.0-1017-azure

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

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