Name | pycloudevents JSON |
Version |
0.1.4
JSON |
| download |
home_page | None |
Summary | A third party cloudevents 1.0 SDK for Python. |
upload_time | 2024-04-16 06:40:42 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.11 |
license | Apache2.0 |
keywords |
cloudevents
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# PyCloudEvents
This Python library defines a CloudEvent class that represents a CloudEvent object according to the [CloudEvents specification](https://www.cncf.io/projects/cloudevents/).
## TOC
- [PyCloudEvents](#pycloudevents)
- [TOC](#toc)
- [Installation](#installation)
- [Usage](#usage)
- [Creating a CloudEvent object](#creating-a-cloudevent-object)
- [Serializing a CloudEvent object to JSON](#serializing-a-cloudevent-object-to-json)
- [Deserializing a JSON string to a CloudEvent object](#deserializing-a-json-string-to-a-cloudevent-object)
- [CloudEvent Attributes](#cloudevent-attributes)
- [Contributing](#contributing)
## Installation
```shell
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:
```python
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:
```python
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:
```python
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:
```python
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:
```python
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:
```python
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](./CONTRIBUTING.md)
Raw data
{
"_id": null,
"home_page": null,
"name": "pycloudevents",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.11",
"maintainer_email": null,
"keywords": "cloudevents",
"author": null,
"author_email": "-LAN- <laipz8200@outlook.com>",
"download_url": "https://files.pythonhosted.org/packages/95/b7/2f0ea8685ad1303842bf830852a8cff2b59887f268569bb649be3f0e0cbb/pycloudevents-0.1.4.tar.gz",
"platform": null,
"description": "# PyCloudEvents\n\nThis Python library defines a CloudEvent class that represents a CloudEvent object according to the [CloudEvents specification](https://www.cncf.io/projects/cloudevents/).\n\n## TOC\n\n- [PyCloudEvents](#pycloudevents)\n - [TOC](#toc)\n - [Installation](#installation)\n - [Usage](#usage)\n - [Creating a CloudEvent object](#creating-a-cloudevent-object)\n - [Serializing a CloudEvent object to JSON](#serializing-a-cloudevent-object-to-json)\n - [Deserializing a JSON string to a CloudEvent object](#deserializing-a-json-string-to-a-cloudevent-object)\n - [CloudEvent Attributes](#cloudevent-attributes)\n - [Contributing](#contributing)\n\n## Installation\n\n```shell\npip install pycloudevents\n```\n\n## Usage\n\nThe `CloudEvent` class provides methods to create, serialize (convert to JSON), and deserialize CloudEvents.\n\n### Creating a CloudEvent object\n\nThere are four ways to create a `CloudEvent` object:\n\nUsing keyword arguments in the constructor:\n\n```python\nfrom pycloudevents import CloudEvent\n\nevent = CloudEvent(\n id=\"my-id\",\n source=\"https://example.com/source\",\n type=\"com.cloudevents.example.extension\",\n data={\"message\": \"Hello, world!\"},\n)\n```\n\nFrom a dictionary:\n\n```python\nfrom pycloudevents import CloudEvent\n\ndata = {\n \"id\": \"12345\",\n \"specversion\": \"1.0\",\n \"type\": \"com.cloudevents.example.extension\",\n \"source\": \"https://example.com/source\",\n \"data\": {\"message\": \"Hello, world!\"},\n}\n\nevent = CloudEvent.from_dict(data)\n```\n\nFrom a mapping object:\n\n```python\nfrom pycloudevents import CloudEvent\n\ndata = {\n \"id\": \"12345\",\n \"specversion\": \"1.0\",\n \"type\": \"com.cloudevents.example.extension\",\n \"source\": \"https://example.com/source\",\n \"data\": {\"message\": \"Hello, world!\"},\n}\n\nevent = CloudEvent.from_mapping(data)\n```\n\nFrom a JSON string:\n\n```python\nfrom pycloudevents import CloudEvent\n\njson_string = '{\"id\": \"12345\", \"specversion\": \"1.0\", \"type\": \"com.cloudevents.example.extension\", \"source\": \"https://example.com/source\", \"data\": {\"message\": \"Hello, world!\"}}'\n\nevent = CloudEvent.from_json(json_string)\n```\n\n### Serializing a CloudEvent object to JSON\n\nThe `to_structured` method converts a `CloudEvent` object to a JSON string:\n\n```python\nfrom pycloudevents import CloudEvent\n\nevent = CloudEvent(...) # Create an event object\n\njson_data = event.to_structured()\nprint(json_data)\n```\n\n### Deserializing a JSON string to a CloudEvent object\n\nThe `from_json` class method creates a `CloudEvent` object from a JSON string:\n\n```python\nfrom pycloudevents import CloudEvent\n\njson_string = '{\"specversion\": \"1.0\", ...}' # Your JSON string\n\nevent = CloudEvent.from_json(json_string)\n```\n\n## CloudEvent Attributes\n\nThe `CloudEvent` class includes the following attributes according to the CloudEvents specification:\n\n- `id`: (str) The identifier of the event.\n- `source`: (str) The source of the event.\n- `specversion`: (str) The CloudEvents specification version (default is \"1.0\").\n- `type`: (str) The type of the event.\n- `datacontenttype`: (Optional[str]) The data content type (default is None).\n- `dataschema`: (Optional[str]) The data schema (default is None).\n- `subject`: (Optional[str]) The subject of the event (default is None).\n- `time`: (Optional[str]) The timestamp of the event (default is None).\n- `data`: (Any) The data associated with the event (default is None).\n- `extensions`: (Hashable) Additional extensions for the event.\n\n## Contributing\n\nSee more in our [Contributing Guidelines](./CONTRIBUTING.md)\n",
"bugtrack_url": null,
"license": "Apache2.0",
"summary": "A third party cloudevents 1.0 SDK for Python.",
"version": "0.1.4",
"project_urls": {
"Changelog": "https://github.com/laipz8200/pycloudevents/blob/main/CHANGELOG.md",
"Documentation": "https://github.com/laipz8200/pycloudevents/blob/main/README.md",
"Homepage": "https://github.com/laipz8200/pycloudevents",
"Repository": "https://github.com/laipz8200/pycloudevents"
},
"split_keywords": [
"cloudevents"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "e536d232f0d99ba03ece8cdc4359e8dcd342519eac5bf32a317bd218a4ca7cd6",
"md5": "36cdd68551fe8ad188148d22b671159b",
"sha256": "97a62222f3a2e6456b9e71bb185de8fffd8fc4bb0118892326ae293c3e07f0ca"
},
"downloads": -1,
"filename": "pycloudevents-0.1.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "36cdd68551fe8ad188148d22b671159b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.11",
"size": 8707,
"upload_time": "2024-04-16T06:40:40",
"upload_time_iso_8601": "2024-04-16T06:40:40.636310Z",
"url": "https://files.pythonhosted.org/packages/e5/36/d232f0d99ba03ece8cdc4359e8dcd342519eac5bf32a317bd218a4ca7cd6/pycloudevents-0.1.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "95b72f0ea8685ad1303842bf830852a8cff2b59887f268569bb649be3f0e0cbb",
"md5": "81180745e2729eec2f4fc3a400bdc28f",
"sha256": "e1ee031e9ec8c4ee81bd2c4bf677021a625529f79c10ccab0a0de17cca8b089b"
},
"downloads": -1,
"filename": "pycloudevents-0.1.4.tar.gz",
"has_sig": false,
"md5_digest": "81180745e2729eec2f4fc3a400bdc28f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11",
"size": 8023,
"upload_time": "2024-04-16T06:40:42",
"upload_time_iso_8601": "2024-04-16T06:40:42.287723Z",
"url": "https://files.pythonhosted.org/packages/95/b7/2f0ea8685ad1303842bf830852a8cff2b59887f268569bb649be3f0e0cbb/pycloudevents-0.1.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-16 06:40:42",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "laipz8200",
"github_project": "pycloudevents",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pycloudevents"
}