---
title: SPARQL introspection functions
url: https://docs.triply.cc/reference/introspection/
description: SPARQL functions in TriplyDB that return data about the current environment, such as the
  name and URL of the current user.
---

# SPARQL introspection functions

TriplyDB provides SPARQL functions that can be used to obtain data about the current working environment. Examples are the name and URL of the current dataset, or the name and URL of the current user. This concept is called *introspection*. They are useful whenever a query has to adapt to its context rather than being written for one dataset or one person.

Introspection is supported only by Speedy, TriplyDB's built-in SPARQL engine. A query that uses these functions, saved or not, must run on Speedy rather than on a Virtuoso or Jena service.

All the introspection functions are identified by IRIs in the namespace `https://triplydb.com/Triply/function/`. In the rest of this page, the following prefix is assumed:

```sparql
prefix tf: <https://triplydb.com/Triply/function/>
```

## The functions

The table below lists the introspection functions and the datatype of their result. The introspection functions do not need input parameters.

| **Function** | **Returns datatype**   | **Explanation** |
| --- | --- | --- |
| tf:instance_url() | xsd:anyURI | The URL of the TriplyDB instance |
| tf:authenticated_user_url() | xsd:anyURI | The URL of the user executing the SPARQL query |
| tf:authenticated_user_name() | xsd:string | The name of the user executing the SPARQL query |
| tf:queried_dataset_url() | xsd:anyURI | The URL of the dataset that is being queried |
| tf:queried_dataset_name() | xsd:string | The name of the dataset that is being queried |
| tf:queried_dataset_owner_url() | xsd:anyURI | The URL of the owner of the dataset that is being queried |
| tf:queried_dataset_owner_name() | xsd:string | The name of the owner of the dataset that is being queried |

## Example: a personalised overview

One way in which introspection functions can be put to use is in making dynamic overviews in [data stories](https://docs.triply.cc/how-to/data-stories/). The example below shows how the URL of the current user can be matched to provenance data in the [Editor](https://docs.triply.cc/how-to/edit-skos-data/) to create a personalised overview of Editor operations:

```sparql
prefix tf: <https://triplydb.com/Triply/function/>
prefix editor: <https://triplydb.com/Triply/TriplyDB-instance-editor-vocabulary/>
select ?action ?time
where {
  bind (iri(tf:authenticated_user_url()) as ?userIri)
  ?event
    editor:actor ?userIri ;
    editor:action ?action ;
    editor:time ?time
  .
}
```

Note the `iri()` around the function call. The function returns a URI-typed literal, and it has to be turned into an IRI before it can match a term in the data.

## Related

- [SPARQL: the basics](https://docs.triply.cc/concepts/sparql-basics/) — `bind` and the rest of the syntax used above
- [Query data](https://docs.triply.cc/how-to/query-data/) — running a query in the SPARQL IDE
