Skip to content

Repository files navigation

ISDuBA Python Client

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.

Installation

pip install isduba

Usage

First, 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)

Get documents

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)

Usage Logic

Things to know:

  1. Every path/method combo becomes a Python module with four functions:

    1. sync: Blocking request that returns parsed data (if successful) or None
    2. sync_detailed: Blocking request that always returns a Request, optionally with parsed set if the request was successful.
    3. asyncio: Like sync but async instead of blocking
    4. asyncio_detailed: Like sync_detailed but async instead of blocking
  2. All path/query params, and bodies become method arguments.

  3. If your endpoint had any tags on it, the first tag will be used as a module name for the function (my_tag above)

  4. Any endpoint which did not have a tag will be in isduba.api.default

Typing

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)

Advanced customizations

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]}},
)

About

A python client library for accessing the API of ISDuBA

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages