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.
- ApiError
Detail - Details about API errors.
- ApiError
Message - CDF error message.
- ApiError
Wrapper - Wrapper around an error from CDF.
- Authenticator
- Simple OIDC authenticator.
- Authenticator
Config - Configuration for authentication using the OIDC authenticator
- Authenticator
Error - Error from an authenticator request.
- Authenticator
Middleware - Middleware for token authentication.
- Authenticator
Result - Result from getting a token, including expiry time.
- Builder
- Fluent API for configuring a client.
- CdfApi
Error - An Error from the CDF API.
- Client
Config - Configuration object for a cognite client.
- Cognite
Client - Client object for the CDF API.
- Cognite
External Id - Wrapper around a cognite external ID.
- Cognite
Id - Wrapper around a cognite internal ID.
- Cursor
- Extra fields for
Itemstypes with cursor data. - Custom
Retry Middleware - Middleware for retrying requests.
- Filter
- A type wrapping a CDF filter, with cursor and limit.
- Identity
List - 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.
- Identity
OrInstance List - 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.
- Ignore
Unknown Ids - Extra fields for
Itemstypes with theignoreUnknownIdsfield. - Items
- A generic structure for handling items in requests and responses.
- Json
Response Handler - Response handler for parsing a payload as JSON.
- Limit
Cursor Partition Query - Query with limt, cursor, and partition.
- Limit
Cursor Query - Simple query with limit and cursor.
- Maybe
String U64 - Wrapper around an u64 value that can be deserialized from a string.
- NoResponse
Handler - Response handler for ignoring the response payload on success.
- Parameterized
Property Value - Parameterized value.
- Partition
- A wrapper around a partition, with custom serializer and deserializer
for converting to the
[a]/[b]format used by CDF. - Partitioned
Filter - A wrapper around a filter, with cursor, limit, and partition.
- Patch
- Wrapper around a patch update.
- Proto
Response Handler - Response handler for parsing a payload as Protobuf.
- Range
- A range between two points.
- RawResponse
Handler - Response handler for just returning the raw response.
- Referenced
Property Value - Referenced property value, use the value of a different property.
- Request
Builder - 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.
- Skip
Authentication - This indicates whether or not the API call should skip authentication.
- Update
Set - Update the value of an item.
- Upsert
Options - Options for performing automatic upserts.
Enums§
- Advanced
Filter - Advanced filter. The
filtermodule contains useful tools for building filters. - Aggregate
Filter - Filter for aggregating values.
- Auth
Header Manager - 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.
- Identity
OrInstance - Identity or instance ID.
- Integer
String OrObject - Value that is either an integer or a string.
- Labels
Filter - Filter on labels.
- Query
Value - Value used in complex queries.
- Range
Item - Start or end of a range.
- RawValue
- Raw filter value.
- Update
List - Update the value of a list item, adding and removing or setting the values.
- Update
Map - Update a map from
TKeytoTValue, adding and removing or setting the values. - Update
SetNull - 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.
- Custom
Authenticator - Trait for a custom authenticator. This should set the necessary headers in
headersbefore 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. - Delete
With Ignore Unknown Ids - Trait for resource types that can be deleted with a list of identities and a boolean option to ignore unknown ids.
- Delete
With Request - Trait for resource types that can be deleted with a more complex request.
- Delete
With Response - 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.
- Filter
Items - Trait for resource types that allow filtering with a simple filter.
- Filter
With Request - Trait for resource types that allow filtering with a more complex request.
- From
Error Detail - Trait implemented for types that can be retrieved from an error detail element.
- Into
Params - Trait for query parameters.
- Into
Patch - Trait for converting a value into a patch, used for upsert.
- Into
Patch Item - Trait for converting a value into a patch item, used for upsert.
- Into
Query Range - Trait for types that can be converted into a range for a DMS query.
- List
- Trait for simple GET / endpoints.
- Property
Identifier - Trait for values that can be converted into a property identifier.
- Response
Handler - Trait for a type that produces a typed response from a successful HTTP response message.
- Retrieve
- Trait for retrieving items from CDF by id.
- Retrieve
With Ignore Unknown Ids - Trait for retrieving items from CDF with an option to ignore unknown IDs.
- Retrieve
With Request - Trait for retrieving items from CDF with a more complex request type.
- Search
Items - 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.
- Upsert
Collection - Trait for resource types that support upserts directly.
- With
ApiClient - Trait for a type that contains an API client.
- With
Base Path - Trait for a type with a base path.
- With
Partition - 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
itemto the query with namenameif it is Some. - to_
query_ vec - Push a list of items to the query with name
nameifitemisSome. - to_
query_ vec_ i64 - Push a list of numbers to the query with name
nameifitemisSome.