A client library for accessing ISDuBA API, based on code generated by https://github.com/openapi-generators/openapi-python-client and adapted to ISDuBA-specific needs.
pip install isdubaFirst, create a client instance:
fromisdubaimportClientclient=Client(base_url="https://isduba.example.com")Then, login with your credentials:
client.login(username='ada', password='bob')Now call your endpoint and use your models:
fromisduba.api.defaultimportget_aboutabout=get_about.sync(client=client)
# access the response's value as attributes:about.version# or if you need more info (e.g. status_code)response=get_about.sync_detailed(client=client)Or do the same thing with an async version:
fromisduba.api.defaultimportget_aboutabout=awaitget_about.asyncio(client=client)
response=awaitget_about.asyncio_detailed(client=client)fromisduba.api.defaultimportget_documentsdata=get_documents.sync(client=client, advisories=True, count=1, orders='-critical', limit=10, offset=0)
# search for a stringget_documents.sync(client=client, query='"csaf" search _clientSearch as')
# search for a product. Query syntax: https://github.com/ISDuBA/ISDuBA/blob/main/docs/filter_expr.mddata=get_documents.sync(client=client, query='"putty" ilikepname', limit=2)Things to know:
Every path/method combo becomes a Python module with four functions:
sync: Blocking request that returns parsed data (if successful) orNonesync_detailed: Blocking request that always returns aRequest, optionally withparsedset if the request was successful.asyncio: Likesyncbut async instead of blockingasyncio_detailed: Likesync_detailedbut async instead of blocking
All path/query params, and bodies become method arguments.
If your endpoint had any tags on it, the first tag will be used as a module name for the function (my_tag above)
Any endpoint which did not have a tag will be in
isduba.api.default
All responses are objects, you can add typing information with the models:
fromisduba.modelsimportWebAboutInfofromisduba.api.defaultimportget_aboutfromisduba.typesimportResponseabout: WebAboutInfo=get_about.sync(client=client)
# access the response's value as attributes:about.version# or if you need more info (e.g. status_code)response: Response[WebAboutInfo] =get_about.sync_detailed(client=client)There are more settings on the generated Client class which let you control more runtime behavior, check out the docstring on that class for more info. You can also customize the underlying httpx.Client or httpx.AsyncClient (depending on your use-case):
fromisdubaimportClientdeflog_request(request):
print(f"Request event hook: {request.method}{request.url} - Waiting for response")
deflog_response(response):
request=response.requestprint(f"Response event hook: {request.method}{request.url} - Status {response.status_code}")
client=Client(
base_url="https://isduba.example.com",
httpx_args={"event_hooks": {"request": [log_request], "response": [log_response]}},
)