Postgres Gateway

Users API

Create Users

UsersAPI.create(user: UserWrite) User
UsersAPI.create(user: Sequence[UserWrite]) UserList

Create Users

Create postgres users.

Parameters

user (UserWrite | Sequence[UserWrite]) – The user(s) to create.

Returns

The created user(s)

Return type

User | UserList

Examples

Create user:

>>> import os
>>> from cognite.client import CogniteClient
>>> from cognite.client.data_classes.postgres_gateway import UserWrite, SessionCredentials
>>> from cognite.client.data_classes import ClientCredentials
>>> client = CogniteClient()
>>> session = client.iam.sessions.create(
...     ClientCredentials(os.environ["IDP_CLIENT_ID"], os.environ["IDP_CLIENT_SECRET"]),
...     session_type="CLIENT_CREDENTIALS"
... )
>>> user = UserWrite(credentials=SessionCredentials(nonce=session.nonce))
>>> res = client.postgres_gateway.users.create(user)

Update Users

UsersAPI.update(items: UserUpdate | UserWrite) User
UsersAPI.update(items: Sequence[UserUpdate | UserWrite]) UserList

Update users

Update postgres users

Parameters

items (UserUpdate | UserWrite | Sequence[UserUpdate | UserWrite]) – The user(s) to update.

Returns

The updated user(s)

Return type

User | UserList

Examples

Update user:

>>> import os
>>> from cognite.client import CogniteClient
>>> from cognite.client.data_classes.postgres_gateway import UserUpdate, SessionCredentials
>>> from cognite.client.data_classes import ClientCredentials
>>> client = CogniteClient()
>>> session = client.iam.sessions.create(
...     ClientCredentials(os.environ["IDP_CLIENT_ID"], os.environ["IDP_CLIENT_SECRET"]),
...     session_type="CLIENT_CREDENTIALS"
... )
>>> update = UserUpdate('myUser').credentials.set(SessionCredentials(nonce=session.nonce))
>>> res = client.postgres_gateway.users.update(update)

Delete Users

UsersAPI.delete(username: str | SequenceNotStr[str], ignore_unknown_ids: bool = False) None

Delete postgres user(s)

Delete postgres users

Parameters
  • username (str | SequenceNotStr[str]) – Usernames of the users to delete.

  • ignore_unknown_ids (bool) – Ignore usernames that are not found

Examples

Delete users:

>>> from cognite.client import CogniteClient
>>> client = CogniteClient()
>>> client.postgres_gateway.users.delete(["myUser", "myUser2"])

Retrieve Users

UsersAPI.retrieve(username: str, ignore_unknown_ids: bool = False) User
UsersAPI.retrieve(username: SequenceNotStr[str], ignore_unknown_ids: bool = False) UserList

Retrieve a list of users by their usernames

Retrieve a list of postgres users by their usernames, optionally ignoring unknown usernames

Parameters
  • username (str | SequenceNotStr[str]) – Usernames of the users to retrieve.

  • ignore_unknown_ids (bool) – Ignore usernames that are not found

Returns

The retrieved user(s).

Return type

User | UserList

Examples

Retrieve user:

>>> from cognite.client import CogniteClient
>>> client = CogniteClient()
>>> res = client.postgres_gateway.users.retrieve("myUser", ignore_unknown_ids=True)

List Users

UsersAPI.list(limit: int = 25) UserList

Fetch scoped users

List all users in a given project.

Parameters

limit (int) – Limits the number of results to be returned.

Returns

A list of users

Return type

UserList

Examples

List users:

>>> from cognite.client import CogniteClient
>>> client = CogniteClient()
>>> user_list = client.postgres_gateway.users.list(limit=5)

Iterate over users:

>>> from cognite.client import CogniteClient
>>> client = CogniteClient()
>>> for user in client.postgres_gateway.users:
...     user # do something with the user

Iterate over chunks of users to reduce memory load:

>>> from cognite.client import CogniteClient
>>> client = CogniteClient()
>>> for user_list in client.postgres_gateway.users(chunk_size=25):
...     user_list # do something with the users

User classes

class cognite.client.data_classes.postgres_gateway.SessionCredentials(nonce: 'str')

Bases: CogniteObject

class cognite.client.data_classes.postgres_gateway.User(username: str, created_time: int, last_updated_time: int, session_id: int)

Bases: _UserCore

A user.

This is the read/response format of the user.

Parameters
  • username (str) – Username to authenticate the user on the DB.

  • created_time (int) – The number of milliseconds since 00:00:00 Thursday, 1 January 1970, Coordinated Universal Time (UTC), minus leap seconds.

  • last_updated_time (int) – The number of milliseconds since 00:00:00 Thursday, 1 January 1970, Coordinated Universal Time (UTC), minus leap seconds.

  • session_id (int) – ID of the session tied to this user.

class cognite.client.data_classes.postgres_gateway.UserList(resources: Iterable[Any], cognite_client: CogniteClient | None = None)

Bases: WriteableCogniteResourceList[UserWrite, User]

class cognite.client.data_classes.postgres_gateway.UserWrite(credentials: SessionCredentials | None = None)

Bases: _UserCore

A postgres gateway user (also a typical postgres user) owns the foreign tables (built in or custom).

The created postgres user only has access to use foreign tables and cannot directly create tables users. To create foreign tables use the Postgres Gateway Tables APIs

This is the write/request format of the user.

Parameters

credentials (SessionCredentials | None) – Credentials for authenticating towards CDF using a CDF session.

dump(camel_case: bool = True) dict[str, Any]

Dump the instance into a json serializable Python data type.

Parameters

camel_case (bool) – Use camelCase for attribute names. Defaults to True.

Returns

A dictionary representation of the instance.

Return type

dict[str, Any]

class cognite.client.data_classes.postgres_gateway.UserWriteList(resources: Iterable[Any], cognite_client: CogniteClient | None = None)

Bases: CogniteResourceList[UserWrite]