Skip to content

graphkb

DEFAULT_URL

DEFAULT_URL = 'https://graphkb-api.bcgsc.ca/api'

DEFAULT_LIMIT

DEFAULT_LIMIT = 1000

QUERY_CACHE

QUERY_CACHE: Dict[Any, Any] = {}

class GraphKBConnection

GraphKBConnection.request()

Request wrapper to handle adding common headers and logging

def request(self, endpoint: str, method: str = 'GET', **kwargs) -> Dict:

Args

  • endpoint (str): api endpoint, excluding the base uri
  • method (str): the http method. Defaults to 'GET'.

Returns

  • Dict: the json response as a python dict

GraphKBConnection.post()

Convenience method for making post requests

def post(self, uri: str, data: Dict = {}, **kwargs) -> Dict:

Args

  • uri (str)
  • data (Dict)

Returns

  • Dict

GraphKBConnection.set_cache_data()

Explicitly add a query to the cache

def set_cache_data(self, request_body: Dict, result: List[Record]) -> None:

Args

  • request_body (Dict)
  • result (List[Record])

GraphKBConnection.query()

Query GraphKB

def query(
    self,
    request_body: Dict = {},
    paginate: bool = True,
    ignore_cache: bool = False,
    force_refresh: bool = False,
    limit: int = DEFAULT_LIMIT,
) -> List[Record]:

Args

  • request_body (Dict)
  • paginate (bool)
  • ignore_cache (bool)
  • force_refresh (bool)
  • limit (int)

Returns

join_url()

Join parts of a URL into a full URL

def join_url(base_url: str, *parts) -> str:

Args

  • base_url (str)

Returns

  • str

millis_interval()

start and end are datetime instances

def millis_interval(start: datetime, end: datetime) -> int:

Args

  • start (datetime)
  • end (datetime)

Returns

  • int

cache_key()

create a cache key for a query request to GraphKB

def cache_key(request_body):

Args

  • request_body
Back to top