Crate cognite

Crate cognite 

Source
Expand description

§Cognite Rust SDK

Rust SDK to ensure excellent user experience for developers and data scientists working with the Cognite Data Fusion.

§Documentation

§Prerequisites

Install rust. See instructions here.

Set environment variables:

export COGNITE_BASE_URL="https://api.cognitedata.com"
export COGNITE_CLIENT_ID=<your client id>
export COGNITE_CLIENT_SECRET=<your client secret>
export COGNITE_TOKEN_URL=<your token url>
export COGNITE_SCOPES=<space separated list of scopes>
export COGNITE_PROJECT=<your project name>

§Supported features for API v1

§Core

  • Assets
  • Events
  • Files
  • TimeSeries
    • With protobuf support
  • Sequences

§IAM

  • Groups
  • SecurityCategories
  • Sessions

§Data Ingestion

  • Extraction pipelines
  • Raw

§Data Organization

  • Datasets
  • Labels
  • Relationships

§Data Modeling

  • Instances
  • Spaces
  • Views
  • Containers
  • Streams
  • Records

§Example

Cargo.toml:

[dependencies]
cognite-sdk = { version = "0.6.0" } # See crates.io for latest version.
tokio = { version = "1.23", features = ["macros", "rt-multi-thread"] }
use cognite::prelude::*;
use cognite::{Asset, AssetFilter, AssetSearch, CogniteClient};

#[tokio::main]
fn main() {
    // Create a client from environment variables
    let cognite_client = CogniteClient::new("TestApp", None).unwrap();

    // List all assets
    let mut filter: AssetFilter = AssetFilter::new();
    filter.name = Some("Aker".to_string());
    let assets = cognite_client
        .assets
        .filter(FilterAssetsRequest {
            filter,
            ..Default::default()
        })
        .await
        .unwrap();

    // Retrieve asset
    match cognite_client
        .assets
        .retrieve(&vec![Identity::from(6687602007296940)], false, None)
        .await
        .unwrap();
}

Using the builder pattern to set OIDC credentials:

use cognite::prelude::*;

#[tokio::main]
fn main() {
    let builder = CogniteClient::builder();
    builder
        .set_oidc_credentials(AuthenticatorConfig {
            ...
        })
        .set_project("my_project")
        .set_app_name("TestApp")
        .set_base_url("https://api.cognitedata.com");
    let cognite_client = builder.build().unwrap();
}

§Run examples

cargo run --example client

§Contributing

See Contributing for details.

Modules§

assets
Assets represent objects or groups of objects from the physical world. Assets are organized in hierarchies. For example, a water pump asset can be part of a subsystem asset on an oil platform asset.
datasets
Data sets let you document and track data lineage, as well as restrict access to data.
dto_common
Common types for DTOs.
events
Event objects store complex information about multiple assets over a time period. Typical types of events might include Alarms, Process Data, and Logs.
extpipes
Extraction pipelines represent applications and software running outside CDF.
files
Files store documents, binary blobs, and other file data and relate it to assets.
filter
Structures and methods for creating complex filters.
iam
Groups are used to give principals the capabilities to access CDF resources. One principal can be a member of multiple groups, and one group can have multiple members.
labels
Labels let you annotate resources such as assets and time series.
middleware
Middleware used by the cognite HTTP client.
models
Data modeling lets you create complex data models to model industrial knowledge graphs.
prelude
Prelude containing common types and traits used when working with the SDK. This can be glob-imported for convenience.
raw
Raw is a NoSQL JSON store. Each project can have a variable number of databases, each of which will have a variable number of tables, each of which will have a variable number of key-value objects. Only queries on key are supported through this API.
relationships
Relationships lets you create custom links between different resources.
sequences
A sequence stores a table with up to 400 columns indexed by row number. There can be at most 400 numeric columns and 200 string columns. Each of the columns has a pre-defined type: a string, integer, or floating point number.
time_series
A time series consists of a sequence of data points connected to a single asset. For example, a water pump asset can have a temperature time series that records a data point in units of °C every second.
utils
Utility methods and tooling.

Structs§

ApiClient
API client, used to query CDF.
ApiErrorDetail
Details about API errors.
ApiErrorMessage
CDF error message.
ApiErrorWrapper
Wrapper around an error from CDF.
Authenticator
Simple OIDC authenticator.
AuthenticatorConfig
Configuration for authentication using the OIDC authenticator
AuthenticatorError
Error from an authenticator request.
AuthenticatorMiddleware
Middleware for token authentication.
AuthenticatorResult
Result from getting a token, including expiry time.
Builder
Fluent API for configuring a client.
CdfApiError
An Error from the CDF API.
ClientConfig
Configuration object for a cognite client.
CogniteClient
Client object for the CDF API.
CogniteExternalId
Wrapper around a cognite external ID.
CogniteId
Wrapper around a cognite internal ID.
Cursor
Extra fields for Items types with cursor data.
CustomRetryMiddleware
Middleware for retrying requests.
Filter
A type wrapping a CDF filter, with cursor and limit.
IdentityList
Serializable wrapper around a list of identities. This implements serialize for individual strings or integers. as well as lists of these. This is useful for the many endpoints that accept lists of identities.
IdentityOrInstanceList
Serializable wrapper around a list of identity or instance IDs. This implements serialize for individual strings, integers or instance IDs, as well as lists of these. This is useful for the many endpoints that accept lists of identities.
IgnoreUnknownIds
Extra fields for Items types with the ignoreUnknownIds field.
Items
A generic structure for handling items in requests and responses.
JsonResponseHandler
Response handler for parsing a payload as JSON.
LimitCursorPartitionQuery
Query with limt, cursor, and partition.
LimitCursorQuery
Simple query with limit and cursor.
MaybeStringU64
Wrapper around an u64 value that can be deserialized from a string.
NoResponseHandler
Response handler for ignoring the response payload on success.
ParameterizedPropertyValue
Parameterized value.
Partition
A wrapper around a partition, with custom serializer and deserializer for converting to the [a]/[b] format used by CDF.
PartitionedFilter
A wrapper around a filter, with cursor, limit, and partition.
Patch
Wrapper around a patch update.
ProtoResponseHandler
Response handler for parsing a payload as Protobuf.
Range
A range between two points.
RawResponseHandler
Response handler for just returning the raw response.
ReferencedPropertyValue
Referenced property value, use the value of a different property.
RequestBuilder
Generic request builder. Used to construct custom requests towards CDF.
Resource
A resource instance contains methods for accessing a single CDF resource type.
Search
A type wrapping a CDF filter and search, with limit.
SkipAuthentication
This indicates whether or not the API call should skip authentication.
UpdateSet
Update the value of an item.
UpsertOptions
Options for performing automatic upserts.

Enums§

AdvancedFilter
Advanced filter. The filter module contains useful tools for building filters.
AggregateFilter
Filter for aggregating values.
AuthHeaderManager
Enumeration of the possible authentication methods available.
Error
Cognite SDK Error.
Identity
An Identity represents a CDF resource either by internal ID or external ID.
IdentityOrInstance
Identity or instance ID.
IntegerStringOrObject
Value that is either an integer or a string.
LabelsFilter
Filter on labels.
QueryValue
Value used in complex queries.
RangeItem
Start or end of a range.
RawValue
Raw filter value.
UpdateList
Update the value of a list item, adding and removing or setting the values.
UpdateMap
Update a map from TKey to TValue, adding and removing or setting the values.
UpdateSetNull
Update the value of an item, or set it to null.

Constants§

VERSION
SDK library version.

Traits§

Create
Trait for creating resources with POST / requests.
CustomAuthenticator
Trait for a custom authenticator. This should set the necessary headers in headers before each request. Note that this may be called from multiple places in parallel.
Delete
Trait for resource types that can be deleted with a list of TIdt.
DeleteWithIgnoreUnknownIds
Trait for resource types that can be deleted with a list of identities and a boolean option to ignore unknown ids.
DeleteWithRequest
Trait for resource types that can be deleted with a more complex request.
DeleteWithResponse
Trait for resource types that can be deleted, and where the delete request has a non-empty response.
EqIdentity
Trait indicating that a type can be compared to an identity.
FilterItems
Trait for resource types that allow filtering with a simple filter.
FilterWithRequest
Trait for resource types that allow filtering with a more complex request.
FromErrorDetail
Trait implemented for types that can be retrieved from an error detail element.
IntoParams
Trait for query parameters.
IntoPatch
Trait for converting a value into a patch, used for upsert.
IntoPatchItem
Trait for converting a value into a patch item, used for upsert.
IntoQueryRange
Trait for types that can be converted into a range for a DMS query.
List
Trait for simple GET / endpoints.
PropertyIdentifier
Trait for values that can be converted into a property identifier.
ResponseHandler
Trait for a type that produces a typed response from a successful HTTP response message.
Retrieve
Trait for retrieving items from CDF by id.
RetrieveWithIgnoreUnknownIds
Trait for retrieving items from CDF with an option to ignore unknown IDs.
RetrieveWithRequest
Trait for retrieving items from CDF with a more complex request type.
SearchItems
Trait for resource types that allow filtering with fuzzy search.
SetCursor
Trait implemented by types with a cursor, to allow automatic pagination.
Update
Trait for resource types that can be patch updated.
Upsert
Trait for upserts of resources that support both Create and Update.
UpsertCollection
Trait for resource types that support upserts directly.
WithApiClient
Trait for a type that contains an API client.
WithBasePath
Trait for a type with a base path.
WithPartition
Trait implemented by types with a partition, to allow automatic handling of partitions.

Functions§

get_duplicates_from_result
Given a result object from CDF, if it is a “conflict” error, return the list of identities.
get_instance_properties
Get instance type of special data models type.
get_missing_from_result
Given a result object from CDF, if it is a “missing” error, return the list of identities.
to_query
Push the item given in item to the query with name name if it is Some.
to_query_vec
Push a list of items to the query with name name if item is Some.
to_query_vec_i64
Push a list of numbers to the query with name name if item is Some.

Type Aliases§

ItemsVec
A convenience type for Items using a Vec to store items.
Result
A Result alias where the Err case is cognite::Error.