To authenticate with Encord you must register a public key in the Encord platform. See our documentation here to learn more. Users can only access Projects, Datasets, and Ontologies from within their Workspace.
Authentication must occur every time an SDK script is run.
Ensure your private key is not password protected. All private keys generated on the Encord platform as described in our documentation are not password protected by default.
After registering a public key, use the corresponding private key to authenticate your EncordUserClient. The following code sample needs to be included in all SDK interactions, and hence is included in all code snippets we provide in these tutorials.
We recommend using the file path to your private key, rather than the private key itself when authenticating.
The following script must be added to all Encord SDK scripts. It is present in all complete code examples we provide.
# Import dependenciesfrom encord import EncordUserClient# Authenticate with Encord using the path to your private keyuser_client = EncordUserClient.create_with_ssh_private_key( ssh_private_key_path="<private_key_path>", # For US platform users use "https://api.us.encord.com" domain="https://api.encord.com", )
# Import dependenciesfrom encord import EncordUserClient# Authenticate with Encord using the path to your private keyuser_client = EncordUserClient.create_with_ssh_private_key( ssh_private_key_path="/Users/chris-encord/sdk-ssh-private-key", # For US platform users use "https://api.us.encord.com" domain="https://api.encord.com", )
If a script or service cannot store your private key, you can authenticate with a bearer token instead. Use an SSH-authenticated client to generate the token with get_bearer_token(), then pass the token to EncordUserClient.create_with_bearer_token().
A bearer token grants the same access as your private key. Store it securely and never commit it to version control.
# Import dependenciesfrom encord import EncordUserClient# Authenticate with your private key and generate a bearer tokenssh_client = EncordUserClient.create_with_ssh_private_key( ssh_private_key_path="<private_key_path>", # For US platform users use "https://api.us.encord.com" domain="https://api.encord.com", )bearer_token = ssh_client.get_bearer_token()# Authenticate with Encord using the bearer tokenuser_client = EncordUserClient.create_with_bearer_token( bearer_token, # For US platform users use "https://api.us.encord.com" domain="https://api.encord.com",)# For US platform users, also pass the US domain# user_client = EncordUserClient.create_with_bearer_token(bearer_token, domain="https://api.us.encord.com")
If you are using Encord’s US based hosted platform, ALL authentication for the SDK MUST include the following:
domain="https://api.us.encord.com"
# Import dependenciesfrom encord import EncordUserClient# Authenticate with Encord using the path to your private keyuser_client = EncordUserClient.create_with_ssh_private_key( ssh_private_key_path="<private_key_path>", domain="https://api.us.encord.com",)
# Import dependenciesfrom encord import EncordUserClient# Authenticate with Encord using the path to your private keyuser_client = EncordUserClient.create_with_ssh_private_key( ssh_private_key_path="/Users/chris-encord/sdk-ssh-private-key", domain="https://api.us.encord.com", )