Skip to main content
POST
/
models
/
instances
/
query
Python SDK
from cognite.client.data_classes.data_modeling.query import Query, Select, NodeResultSetExpression, EdgeResultSetExpression, SourceSelector
from cognite.client.data_classes.filters import Range, Equals
from cognite.client.data_classes.data_modeling.ids import ViewId
movie_id = ViewId("mySpace", "MovieView", "v1")
actor_id = ViewId("mySpace", "ActorView", "v1")
query = Query(
    with_ = {
        "movies": NodeResultSetExpression(filter=Range(movie_id.as_property_ref("releaseYear"), lt=2000)),
        "actors_in_movie": EdgeResultSetExpression(from_="movies", filter=Equals(["edge", "type"], {"space": movie_id.space, "externalId": "Movie.actors"})),
        "actors": NodeResultSetExpression(from_="actors_in_movie"),
    },
    select = {
        "actors": Select(
            [SourceSelector(actor_id, ["name"])], sort=[InstanceSort(actor_id.as_property_ref("name"))]),
    },
)
res = client.data_modeling.instances.query(query)

from cognite.client.data_classes.data_modeling.data_types import UnitReference, UnitSystemReference
selected_source = SourceSelector(
    source=ViewId("my-space", "my-xid", "v1"),
    properties=["f32_prop1", "f32_prop2", "f64_prop1", "f64_prop2"],
    target_units=[
        TargetUnit("f32_prop1", UnitReference("pressure:kilopa")),
        TargetUnit("f32_prop2", UnitReference("pressure:barg")),
        TargetUnit("f64_prop1", UnitSystemReference("SI")),
        TargetUnit("f64_prop2", UnitSystemReference("Imperial")),
    ],
)

SourceSelector(source=ViewId("my-space", "my-xid", "v1"), properties=["*"])
{
  "items": {},
  "nextCursor": {},
  "typing": {},
  "debug": {
    "notices": [
      {
        "code": "excessiveTimeout",
        "category": "invalidDebugOptions",
        "level": "warning",
        "hint": "<string>",
        "timeout": 123
      }
    ],
    "translatedQuery": {
      "query": {},
      "parameters": {}
    },
    "plan": {
      "fullPlan": {},
      "profiled": true,
      "byIdentifier": {}
    },
    "llmPrompt": "<string>"
  }
}

Authorizations

Authorization
string
header
required

Access token issued by the CDF project's configured identity provider. Access token must be an OpenID Connect token, and the project must be configured to accept OpenID Connect tokens. Use a header key of 'Authorization' with a value of 'Bearer $accesstoken'. The token can be obtained through any flow supported by the identity provider.

Body

application/json

Query specification.

with
object
required
select
object
required

Select properties for each result set.

cursors
object

Cursors returned from the previous query request. These cursors match the result set expressions you specified in the with clause for the query.

parameters
object

Values in filters can be parameterised. Parameters are provided as part of the query object, and referenced in the filter itself.

includeTyping
boolean
default:false

Should we return property type information as part of the result?

debug
object

Return query debug notices.

Response

Matching nodes and edges

items
object
required
nextCursor
object
required
typing
object

Property type information for selected result expressions.

debug
object

Contains debug notices if debug flag is set in the query.

Last modified on April 23, 2026