Name | doip_sdk JSON |
Version |
0.0.6
JSON |
| download |
home_page | None |
Summary | The SDK for the development of DOIP |
upload_time | 2024-11-28 13:43:31 |
maintainer | None |
docs_url | None |
author | Triet Doan |
requires_python | <4.0,>=3.11 |
license | None |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# DOIP-SDK
This is the Software Development Kit (SDK) for DOIP implementation in Python. It provides a template for DOIP servers as
well as some utility methods to facilitate the implementation. Please check our [documentation page][1].
## Installation
This package requires Python version `>=3.11`. To install it, run:
```shell
# Using pip
$ pip install doip-sdk
# Using poetry
$ poetry add doip-sdk
```
When using `doip-sdk` to develop a server, it has feature to automatically generate a self-signed certificate when none
is provided. To enable this feature, please install it with the `ssl` extra as follows:
```shell
# Using pip
$ pip install "doip-sdk[ssl]"
# Using poetry
$ poetry add "doip-sdk[ssl]"
```
## Quick start
### Server side
Suppose that we want to implement a server, which speaks DOIP. For that, we first need to create a handler. A handler is
a component which handles incoming requests. Below is an example handler, which simply returns a success message.
```python
from collections.abc import Iterator
from doip_sdk import DOIPHandler, ServerResponse, ResponseStatus, write_json_segment, write_empty_segment, DOIPServer
class ExampleHandler(DOIPHandler):
def hello(self, first_segment: dict, _: Iterator[bytearray]):
response = ServerResponse(status=ResponseStatus.SUCCESS)
write_json_segment(
socket=self.request,
message=response.model_dump(exclude_none=True)
)
write_empty_segment(socket=self.request)
if __name__ == '__main__':
HOST, PORT = 'localhost', 9999
with DOIPServer(HOST, PORT, ExampleHandler) as server:
server.start()
```
On line 18, we create a server instance, which uses the `ExampleHandler`, and start it. According to the
[DOIP Specification][2], all communication must take place over a secured channel. Therefore, if a private key and a
certificate are not provided, the `DOIPServer` generates a self-signed certificate and use it.
To stop the server, simply press <kbd>ctrl</kbd> + <kbd>c</kbd>.
The `ExampleHandler` above overrides the `hello` method, which is called when a `0.DOIP/Op.Hello` operation is
received. Currently, these methods below can be overridden:
* `hello`
* `create`
* `retrieve`
* `update`
* `delete`
* `search`
* `list_operation`
* `extended_operation`
All of them have the same signature, where the first parameter (except `self`) is the first segment in the request,
and the second parameter is an `Iterator[bytearray]`, which can be used to read other segments in the message.
Each method will be called respectively based on the `operationId` from the client. If the `operationId` does not
refer to a basic operation, the `extended_operation` method will be triggered instead. It is not required to implement
all those methods. If the client asks for an unsupported operation, an error message will be automatically returned.
### Client side
An example client for the server above can be implemented as follows:
```python
from doip_sdk import send_request
if __name__ == '__main__':
host, port = 'localhost', 9999
data = {
'operationId': '0.DOIP/Op.Hello'
}
response = send_request(host=host, port=port, payload=[data])
for segment in response.content:
print(segment.decode('utf-8'))
```
The example client sends a request with the `Hello` operation and print out the response.
[1]: https://doip.pages-ce.gwdg.de/doip-sdk/
[2]: https://www.dona.net/sites/default/files/2018-11/DOIPv2Spec_1.pdf
Raw data
{
"_id": null,
"home_page": null,
"name": "doip_sdk",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.11",
"maintainer_email": null,
"keywords": null,
"author": "Triet Doan",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/34/7f/af9619915bcdbea113280cb80efd6861fdd3d4c1fed87ba85792382eaa41/doip_sdk-0.0.6.tar.gz",
"platform": null,
"description": "# DOIP-SDK\n\nThis is the Software Development Kit (SDK) for DOIP implementation in Python. It provides a template for DOIP servers as\nwell as some utility methods to facilitate the implementation. Please check our [documentation page][1].\n\n## Installation\n\nThis package requires Python version `>=3.11`. To install it, run:\n\n```shell\n# Using pip\n$ pip install doip-sdk\n\n# Using poetry\n$ poetry add doip-sdk\n```\n\nWhen using `doip-sdk` to develop a server, it has feature to automatically generate a self-signed certificate when none\nis provided. To enable this feature, please install it with the `ssl` extra as follows:\n\n```shell\n# Using pip\n$ pip install \"doip-sdk[ssl]\"\n\n# Using poetry\n$ poetry add \"doip-sdk[ssl]\"\n```\n\n## Quick start\n\n### Server side\n\nSuppose that we want to implement a server, which speaks DOIP. For that, we first need to create a handler. A handler is\na component which handles incoming requests. Below is an example handler, which simply returns a success message.\n\n```python\nfrom collections.abc import Iterator\n\nfrom doip_sdk import DOIPHandler, ServerResponse, ResponseStatus, write_json_segment, write_empty_segment, DOIPServer\n\n\nclass ExampleHandler(DOIPHandler):\n def hello(self, first_segment: dict, _: Iterator[bytearray]):\n response = ServerResponse(status=ResponseStatus.SUCCESS)\n write_json_segment(\n socket=self.request,\n message=response.model_dump(exclude_none=True)\n )\n write_empty_segment(socket=self.request)\n\n\nif __name__ == '__main__':\n HOST, PORT = 'localhost', 9999\n with DOIPServer(HOST, PORT, ExampleHandler) as server:\n server.start()\n```\n\nOn line 18, we create a server instance, which uses the `ExampleHandler`, and start it. According to the\n[DOIP Specification][2], all communication must take place over a secured channel. Therefore, if a private key and a\ncertificate are not provided, the `DOIPServer` generates a self-signed certificate and use it.\n\nTo stop the server, simply press <kbd>ctrl</kbd> + <kbd>c</kbd>.\n\nThe `ExampleHandler` above overrides the `hello` method, which is called when a `0.DOIP/Op.Hello` operation is\nreceived. Currently, these methods below can be overridden:\n\n* `hello`\n* `create`\n* `retrieve`\n* `update`\n* `delete`\n* `search`\n* `list_operation`\n* `extended_operation`\n\nAll of them have the same signature, where the first parameter (except `self`) is the first segment in the request,\nand the second parameter is an `Iterator[bytearray]`, which can be used to read other segments in the message.\n\nEach method will be called respectively based on the `operationId` from the client. If the `operationId` does not\nrefer to a basic operation, the `extended_operation` method will be triggered instead. It is not required to implement\nall those methods. If the client asks for an unsupported operation, an error message will be automatically returned.\n\n### Client side\n\nAn example client for the server above can be implemented as follows:\n\n```python\nfrom doip_sdk import send_request\n\nif __name__ == '__main__':\n host, port = 'localhost', 9999\n data = {\n 'operationId': '0.DOIP/Op.Hello'\n }\n response = send_request(host=host, port=port, payload=[data])\n\n for segment in response.content:\n print(segment.decode('utf-8'))\n```\n\nThe example client sends a request with the `Hello` operation and print out the response.\n\n[1]: https://doip.pages-ce.gwdg.de/doip-sdk/\n[2]: https://www.dona.net/sites/default/files/2018-11/DOIPv2Spec_1.pdf\n",
"bugtrack_url": null,
"license": null,
"summary": "The SDK for the development of DOIP",
"version": "0.0.6",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b81f50d66a122920db57b1224c42528749c82f019d9ca3c01d4b6480402055bf",
"md5": "8abc4960a6580772b65e17821b5d88dc",
"sha256": "9f56594562c1881a08f9bc924698ce40c9007c49471ea8668a292f87dbebe2e7"
},
"downloads": -1,
"filename": "doip_sdk-0.0.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8abc4960a6580772b65e17821b5d88dc",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.11",
"size": 12265,
"upload_time": "2024-11-28T13:43:30",
"upload_time_iso_8601": "2024-11-28T13:43:30.805616Z",
"url": "https://files.pythonhosted.org/packages/b8/1f/50d66a122920db57b1224c42528749c82f019d9ca3c01d4b6480402055bf/doip_sdk-0.0.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "347faf9619915bcdbea113280cb80efd6861fdd3d4c1fed87ba85792382eaa41",
"md5": "60e8613e4bb7b3b88cfc7451ed0cc2c8",
"sha256": "c07c10e10c3984fee159d13f5672f38db3c953bbd810b1fda658c2aa0b241394"
},
"downloads": -1,
"filename": "doip_sdk-0.0.6.tar.gz",
"has_sig": false,
"md5_digest": "60e8613e4bb7b3b88cfc7451ed0cc2c8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.11",
"size": 17617,
"upload_time": "2024-11-28T13:43:31",
"upload_time_iso_8601": "2024-11-28T13:43:31.843342Z",
"url": "https://files.pythonhosted.org/packages/34/7f/af9619915bcdbea113280cb80efd6861fdd3d4c1fed87ba85792382eaa41/doip_sdk-0.0.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-28 13:43:31",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "doip_sdk"
}