Skip to content

Client

The SpeckleClient is your entry point for interacting with your Speckle Server's GraphQL API. You'll need to have access to a server to use it, or you can use our public server app.speckle.systems.

To authenticate the client, you'll need to have downloaded the Speckle Manager and added your account.

from specklepy.api.client import SpeckleClient
from specklepy.core.api.inputs.project_inputs import ProjectCreateInput
from specklepy.api.credentials import get_default_account

# initialise the client
client = SpeckleClient(host="app.speckle.systems") # or whatever your host is
# client = SpeckleClient(host="localhost:3000", use_ssl=False) or use local server

# authenticate the client with an account
# (account has been added in Speckle Manager)
account = get_default_account()
client.authenticate_with_account(account)

# create a new project
input = ProjectCreateInput(name="a shiny new project")
project = self.project.create(input)

# or, use a project id to get an existing project from the server
new_stream = client.project.get("abcdefghij")
Source code in src/specklepy/api/client.py
def __init__(
    self,
    host: str = DEFAULT_HOST,
    use_ssl: bool = USE_SSL,
    verify_certificate: bool = True,
) -> None:
    super().__init__(
        host=host,
        use_ssl=use_ssl,
        verify_certificate=verify_certificate,
    )
    self.account = Account()

DEFAULT_HOST class-attribute instance-attribute

DEFAULT_HOST = 'app.speckle.systems'

USE_SSL class-attribute instance-attribute

USE_SSL = True

account instance-attribute

account = Account()

authenticate_with_token

authenticate_with_token(token: str) -> None

Authenticate the client using a personal access token. The token is saved in the client object and a synchronous GraphQL entrypoint is created

Source code in src/specklepy/api/client.py
def authenticate_with_token(self, token: str) -> None:
    """
    Authenticate the client using a personal access token.
    The token is saved in the client object and a synchronous GraphQL
    entrypoint is created

    Arguments:
        token {str} -- an api token
    """
    metrics.track(
        metrics.SDK, self.account, {"name": "Client Authenticate With Token"}
    )
    return super().authenticate_with_token(token)

authenticate_with_account

authenticate_with_account(account: Account) -> None

Authenticate the client using an Account object The account is saved in the client object and a synchronous GraphQL entrypoint is created

Source code in src/specklepy/api/client.py
def authenticate_with_account(self, account: Account) -> None:
    """Authenticate the client using an Account object
    The account is saved in the client object and a synchronous GraphQL
    entrypoint is created

    Arguments:
        account {Account} -- the account object which can be found with
        `get_default_account` or `get_local_accounts`
    """
    metrics.track(
        metrics.SDK, self.account, {"name": "Client Authenticate With Account"}
    )
    return super().authenticate_with_account(account)