caltechads / brigid-api-client

Python API client for Brigid

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

brigid-api-client

A client library for accessing Brigid API.

Usage

First, create a client:

from brigid_api_client import AuthenticatedClient

client = AuthenticatedClient(base_url="https://brigid-prod.api.caltech.edu", token="SuperSecretToken")

Now call your endpoint and use your models. Example::

from brigid_api_client.models import Organization
from brigid_api_client.api.organizations import organizations_retrieve
from brigid_api_client.types import Response

org: Organization = organizations_retrieve.sync(client=client, id=1)
# or if you need more info (e.g. status_code)
response: Response[Organization] = organizations_retrieve.sync_detailed(client=client, id=1)

Or do the same thing with an async version:

from brigid_api_client.models import Organization
from brigid_api_client.async_api.organizations import organizations_retrieve
from brigid_api_client.types import Response

org: Organization = await organizations_retrieve.asyncio(client=client, id=1)
response: Response[Organization] = await organizations_retrieve.asyncio_detailed(client=client, id=1)

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 the async instead of blocking
    4. asyncio_detailed: Like sync_detailed by 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 (e.g. organzations above)

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

Updating this client from your local copy of Brigid

First you should have openapi-python-client installed into your global python interpreter.

$ cd ..
$ wget --no-check-certificate -O schema.yml https://localhost:8063/api/v1/schema/
$ openapi-python-client update --path schema.yml  --custom-template-path=./brigid-api-client/templates/  

About

Python API client for Brigid

License:Other


Languages

Language:Python 99.1%Language:HTML 0.9%Language:Makefile 0.0%