@@ -76,8 +76,63 @@ In this topic you'd find various example how to integrate an SDK with various HT
7676
7777### Python requests
7878
79+ One of popular framework is [ 0.2-force-improvements] ( http://docs.python-requests.org/en/master/ ) .
7980
8081
82+ #### CloudEvent to request
83+
84+ The code below shows how integrate both libraries in order to convert a CloudEvent into an HTTP request:
85+
86+ ``` python
87+ def run_binary (event , url ):
88+ binary_headers, binary_data = http_marshaller.ToRequest(
89+ event, converters.TypeBinary, json.dumps)
90+
91+ print (" binary CloudEvent" )
92+ for k, v in binary_headers.items():
93+ print (" {0} : {1} \r\n " .format(k, v))
94+ print (binary_data.getvalue())
95+ response = requests.post(url,
96+ headers = binary_headers,
97+ data = binary_data.getvalue())
98+ response.raise_for_status()
99+
100+
101+ def run_structured (event , url ):
102+ structured_headers, structured_data = http_marshaller.ToRequest(
103+ event, converters.TypeStructured, json.dumps
104+ )
105+ print (" structured CloudEvent" )
106+ print (structured_data.getvalue())
107+
108+ response = requests.post(url,
109+ headers = structured_headers,
110+ data = structured_data.getvalue())
111+ response.raise_for_status()
112+
113+ ```
114+
115+ Complete example of turning a CloudEvent into a request you can find [ here] ( samples/python-requests/cloudevent_to_request.py ) .
116+
117+ #### Request to CloudEvent
118+
119+ The code below shows how integrate both libraries in order to create a CloudEvent from an HTTP request:
120+ ``` python
121+ response = requests.get(url)
122+ response.raise_for_status()
123+ headers = response.headers
124+ data = io.BytesIO(response.content)
125+ event = v02.Event()
126+ http_marshaller = marshaller.NewDefaultHTTPMarshaller()
127+ event = http_marshaller.FromRequest(
128+ event, headers, data, json.load)
129+
130+ ```
131+ Complete example of turning a CloudEvent into a request you can find [ here] ( samples/python-requests/request_to_cloudevent.py ) .
132+
133+
134+ ## SDK versioning
135+
81136The goal of this package is to provide support for all released versions of CloudEvents, ideally while maintaining
82137the same API. It will use semantic versioning with following rules:
83138* MAJOR version increments when backwards incompatible changes is introduced.
0 commit comments