The SDK for the development of DOIP
Project description
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.
Installation
This package requires Python version >=3.11. To install it, run:
# 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:
# 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.
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, 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 ctrl + c.
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:
hellocreateretrieveupdatedeletesearchlist_operationextended_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:
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file doip_sdk-0.0.7.tar.gz.
File metadata
- Download URL: doip_sdk-0.0.7.tar.gz
- Upload date:
- Size: 17.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.11.4 Darwin/23.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c731d83e5605dc752268cb1f039b2b5f719ec968c8e1296cdbbb722aabcdb9e
|
|
| MD5 |
1cabc5c1b7484dbc6424a7d6c04a6410
|
|
| BLAKE2b-256 |
7982e93c8e73afe2a21221c4342883e30e89dea0a43c6a5bb6d0c1f752848994
|
File details
Details for the file doip_sdk-0.0.7-py3-none-any.whl.
File metadata
- Download URL: doip_sdk-0.0.7-py3-none-any.whl
- Upload date:
- Size: 12.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.11.4 Darwin/23.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30c7ecac7f473d2e85aefc035a05f6c6abdc0c8f548e339f412e3f3e561265e3
|
|
| MD5 |
70c227daff26fad0919bea71e2f711b7
|
|
| BLAKE2b-256 |
fa9427f7209cc01a183ff7a1574b345c97b78d2c70b88bc3a11d5edc6842baaf
|