splitgraph.cloud package

Module contents

Public API for interacting with the Splitgraph registry

class splitgraph.cloud.AuthAPIClient(remote: str)

Bases: object

Client for the Splitgraph registry auth API that generates tokens to access other Splitgraph services.

Currently incomplete with just enough methods to allow to register and access the Splitgraph registry via the command line.

property access_token

Will return an up-to-date access token by either getting it from the configuration file or contacting the auth service for a new one. Will write the new access token into the configuration file.

Returns

Access token.

create_machine_credentials(access_token: str, password: str)requests.models.Response

Generate a key and secret that can be used to log into the Splitgraph registry via a normal Postgres connection. The secret must be stored in the user’s local configuration file (it’s not stored on Splitgraph servers).

Parameters
  • access_token – Access token

  • password – Password

Returns

Tuple of (key, secret).

get_access_token(refresh_token: str)requests.models.Response

Get a new access token from a refresh token.

Parameters

refresh_token – Refresh token

Returns

New access token.

get_access_token_from_api(api_key: str, api_secret: str)requests.models.Response

Get a new access token from API keys

Parameters
  • api_key – API key

  • api_secret – API secret

Returns

New access token.

get_latest_version()Optional[str]
get_refresh_token(username: str, password: str)requests.models.Response

Get a long-lived refresh token and a short-lived access token from the API.

Parameters
  • username – Username

  • password – Password

Returns

Tuple of (access_token, refresh_token).

register(username: str, password: str, email: str, accept_tos: bool)requests.models.Response

Register a new Splitgraph user.

Parameters
  • username – Username

  • password – Password

  • email – Email

  • accept_tos – Accept the Terms of Service if they exist

tos()requests.models.Response

Get a Terms of Service message from the registry (if accepting ToS is required) :return: Link to the Terms of Service or None

class splitgraph.cloud.GQLAPIClient(remote: str)

Bases: object

Wrapper class for select Splitgraph Registry GQL operations that can be called from the CLI

find_repository(query: str, limit: int = 10)Tuple[int, List[Tuple[str, str, str]]]
upsert_description(namespace: str, repository: str, description: str)
upsert_metadata(*args, **kwargs)
upsert_readme(namespace: str, repository: str, readme: str)
upsert_topics(namespace: str, repository: str, topics: List[str])
splitgraph.cloud.expect_result(result: List[str], ignore_status_codes: Optional[List[int]] = None)Callable[[Callable[[], requests.models.Response]], Callable[[], Union[str, Tuple[str]]]]

A decorator that can be wrapped around a function returning a requests.Response with a JSON body. If the request has failed, it will extract the “error” from the JSON response and raise an AuthAPIError.

Parameters
  • result – Items to extract. Will raise an AuthAPIError if not all items were fetched.

  • ignore_status_codes – If one of these status codes is returned (e.g. 404), it gets ignored and a None is returned instead.

Returns

Tuple of items enumerated in the result list. If there’s only one item, it will return just that item.

splitgraph.cloud.get_headers()
splitgraph.cloud.get_remote_param(remote: str, key: str)str
splitgraph.cloud.get_token_claim(jwt, claim)

Extract a claim from a JWT token without validating it.

splitgraph.cloud.handle_gql_errors(func: Callable[[], requests.models.Response])Callable[[], requests.models.Response]

A decorator that handles responses from the GQL API, transforming errors into exceptions.