Postgres Gateway
Postgres Gateway Users API
Create Postgres Gateway Users
- UsersAPI.create( ) UserCreated | UserCreatedList
-
Create postgres users.
- Parameters:
user (UserWrite | Sequence[UserWrite]) – The user(s) to create.
- Returns:
The created user(s)
- Return type:
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 Postgres Gateway Users
- UsersAPI.update( ) User | UserList
-
Update postgres users
- Parameters:
items (UserUpdate | UserWrite | Sequence[UserUpdate | UserWrite]) – The user(s) to update.
- Returns:
The updated user(s)
- Return type:
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 Postgres Gateway Users
- UsersAPI.delete(
- username: str | SequenceNotStr[str],
- ignore_unknown_ids: bool = False,
-
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 Postgres Gateway Users
- UsersAPI.retrieve(
- username: str | SequenceNotStr[str],
- ignore_unknown_ids: bool = False,
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:
Examples
Retrieve user:
>>> from cognite.client import CogniteClient >>> client = CogniteClient() >>> res = client.postgres_gateway.users.retrieve("myUser", ignore_unknown_ids=True)
List Postgres Gateway Users
- UsersAPI.list(
- limit: int = 25,
-
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:
Examples
List users:
>>> from cognite.client import CogniteClient >>> client = CogniteClient() >>> user_list = client.postgres_gateway.users.list(limit=5)
Iterate over users:
>>> for user in client.postgres_gateway.users: ... user # do something with the user
Iterate over chunks of users to reduce memory load:
>>> for user_list in client.postgres_gateway.users(chunk_size=25): ... user_list # do something with the users
Postgres Gateway Tables API
Create Postgres Gateway Tables
- TablesAPI.create(
- username: str,
- items: TableWrite | Sequence[TableWrite],
-
- Parameters:
username (str) – The name of the username (a.k.a. database) to be managed from the API
items (pg.TableWrite | Sequence[pg.TableWrite]) – The table(s) to create
- Returns:
Created tables
- Return type:
pg.Table | pg.TableList
Examples
Create custom table:
>>> from cognite.client import CogniteClient >>> from cognite.client.data_classes.data_modeling import ViewId >>> from cognite.client.data_classes.postgres_gateway import ViewTableWrite >>> client = CogniteClient() >>> table = ViewTableWrite(tablename="myCustom", options=ViewId(space="mySpace", external_id="myExternalId", version="v1")) >>> res = client.postgres_gateway.tables.create("myUserName",table)
Delete Postgres Gateway Tables
- TablesAPI.delete(
- username: str,
- tablename: str | SequenceNotStr[str],
- ignore_unknown_ids: bool = False,
-
- Parameters:
username (str) – The name of the username (a.k.a. database) to be managed from the API
tablename (str | SequenceNotStr[str]) – The name of the table(s) to be deleted
ignore_unknown_ids (bool) – Ignore table names that are not found
Examples
Delete custom table:
>>> from cognite.client import CogniteClient >>> client = CogniteClient() >>> client.postgres_gateway.tables.delete("myUserName", ["myCustom", "myCustom2"])
Retrieve Postgres Gateway Tables
- TablesAPI.retrieve(
- username: str,
- tablename: str | SequenceNotStr[str],
- ignore_unknown_ids: bool = False,
Retrieve a list of tables by their tables names
Retrieve a list of Postgres tables for a user by their table names, optionally ignoring unknown table names
- Parameters:
username (str) – The username (a.k.a. database) to be managed from the API
tablename (str | SequenceNotStr[str]) – The name of the table(s) to be retrieved
ignore_unknown_ids (bool) – Ignore table names not found
- Returns:
Foreign tables
- Return type:
pg.Table | pg.TableList | None
Examples
Retrieve custom table:
>>> from cognite.client import CogniteClient >>> client = CogniteClient() >>> res = client.postgres_gateway.tables.retrieve("myUserName", 'myCustom')
Get multiple custom tables by id:
>>> res = client.postgres_gateway.tables.retrieve("myUserName", ["myCustom", "myCustom2"])
List Postgres Gateway Tables
- TablesAPI.list(
- username: str,
- include_built_ins: Literal['yes', 'no'] | None = 'no',
- limit: int | None = 25,
-
List all tables in a given project.
- Parameters:
username (str) – The name of the username (a.k.a. database) to be managed from the API
include_built_ins (Literal['yes', 'no'] | None) – Determines if API should return built-in tables or not
limit (int | None) – Limits the number of results to be returned.
- Returns:
Foreign tables
- Return type:
pg.TableList
Examples
List tables:
>>> from cognite.client import CogniteClient >>> client = CogniteClient() >>> custom_table_list = client.postgres_gateway.tables.list("myUserName", limit=5)
Iterate over tables:
>>> for table in client.postgres_gateway.tables: ... table # do something with the custom table
Iterate over chunks of tables to reduce memory load:
>>> for table_list in client.postgres_gateway.tables(chunk_size=25): ... table_list # do something with the custom tables
Postgres Gateway classes
- class cognite.client.data_classes.postgres_gateway.Column(name: 'str', type: 'ColumnType')
Bases:
CogniteResource- 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.ColumnList(
- resources: Iterable[Any],
- cognite_client: CogniteClient | None = None,
Bases:
CogniteResourceList[Column]
- class cognite.client.data_classes.postgres_gateway.RawTable(
- tablename: str,
- options: RawTableOptions,
- columns: ColumnList,
- created_time: int | None = None,
Bases:
TableForeign tables.
This is the read/response format of the raw table.
- Parameters:
tablename (str) – Name of the foreign table.
options (RawTableOptions) – Table options
columns (ColumnList) – Foreign table columns.
created_time (int | None) – Time when the table was created.
- 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.RawTableOptions(database: 'str', table: 'str', primary_key: 'str | None' = None)
Bases:
CogniteObject
- class cognite.client.data_classes.postgres_gateway.RawTableWrite(
- tablename: str,
- options: RawTableOptions,
- columns: Sequence[Column] | ColumnList,
Bases:
TableWriteForeign tables.
This is the read/response format of the raw table.
- Parameters:
tablename (str) – Name of the foreign table.
options (RawTableOptions) – Table options
columns (Sequence[Column] | ColumnList) – Foreign table columns.
- 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.SessionCredentials(nonce: 'str')
Bases:
CogniteObject
- class cognite.client.data_classes.postgres_gateway.Table(tablename: str, created_time: int | None = None)
Bases:
_TableCore,ABCForeign tables.
This is the read/response format of the custom table.
- Parameters:
tablename (str) – Name of the foreign table.
created_time (int | None) – Time when the table was created
- class cognite.client.data_classes.postgres_gateway.TableList(resources: Iterable[Any], cognite_client: CogniteClient | None = None)
Bases:
WriteableCogniteResourceList[TableWrite,Table]
- class cognite.client.data_classes.postgres_gateway.TableWrite(tablename: str)
Bases:
_TableCore,ABCView and create foreign tables for a given user.
This is the write/request format of the table.
- class cognite.client.data_classes.postgres_gateway.TableWriteList(
- resources: Iterable[Any],
- cognite_client: CogniteClient | None = None,
Bases:
CogniteResourceList[TableWrite]
- class cognite.client.data_classes.postgres_gateway.User(
- username: str,
- created_time: int,
- last_updated_time: int,
- session_id: int | None = None,
Bases:
_UserCoreA user.
This is the read/response format of the user for list and retrieve endpoints.
- 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 | None) – ID of the session tied to this user.
- class cognite.client.data_classes.postgres_gateway.UserCreated(
- host: str,
- username: str,
- password: str,
- created_time: int,
- last_updated_time: int,
- session_id: int | None = None,
Bases:
UserA user.
This is the read/response format of the user for the create endpoint
- Parameters:
host (str) – Host of the DB.
username (str) – Username to authenticate the user on the DB.
password (str) – Password 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 | None) – ID of the session tied to this user.
- class cognite.client.data_classes.postgres_gateway.UserCreatedList(
- resources: Iterable[Any],
- cognite_client: CogniteClient | None = None,
Bases:
WriteableCogniteResourceList[UserWrite,UserCreated]
- class cognite.client.data_classes.postgres_gateway.UserList(resources: Iterable[Any], cognite_client: CogniteClient | None = None)
- class cognite.client.data_classes.postgres_gateway.UserWrite(
- credentials: SessionCredentials | None = None,
Bases:
_UserCoreA 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]
- class cognite.client.data_classes.postgres_gateway.ViewTable(
- tablename: str,
- options: ViewId,
- created_time: int | None = None,
Bases:
TableForeign tables.
This is the read/response format of the custom table.
- Parameters:
tablename (str) – Name of the foreign table.
options (ViewId) – Table options
created_time (int | None) – Time when the table was created.
- 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.ViewTableWrite(
- tablename: str,
- options: ViewId,
Bases:
TableWriteForeign tables.
This is the read/response format of the custom table.
- Parameters:
tablename (str) – Name of the foreign table.
options (ViewId) – Table options
- 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]