Skip to main content


LDkit - Linked Data query toolkit for TypeScript developers
function createLens
import { createLens } from "";

Creates an instance of Lens that lets you query and update RDF data via data schema using TypeScript native data types.

In order to create a Lens instance, you need to provide a data schema that describes the data model which serves to translate data between Linked Data and TypeScript native types (see Schema for details).

You can also pass a set of options for LDkit and a query engine that specify the data source, preferred language, etc. (see Options for details).


Example 1

import { createLens, type Options } from "ldkit";
import { dbo, rdfs, xsd } from "ldkit/namespaces";

// Create options for query engine
const options: Options = {
  sources: [""], // SPARQL endpoint
  language: "en", // Preferred language

// Create a schema
const PersonSchema = {
  "@type": dbo.Person,
  name: rdfs.label,
  abstract: dbo.abstract,
  birthDate: {
    "@id": dbo.birthDate,
} as const;

// Create a resource using the data schema and options above
const Persons = createLens(PersonSchema, options);

// List some persons
const persons = await Persons.find({ take: 10 });
for (const person of persons) {
  console.log(; // string
  console.log(person.birthDate); // Date

// Get a particular person identified by IRI
const ada = await Persons.findByIri("");
console.log(ada?.name); // string "Ada Lovelace"
console.log(ada?.birthDate); // Date object of 1815-12-10


schema: T

data schema which extends Schema

options: Options

optional Options - contains LDkit and query engine configuration


Lens instance that provides interface to Linked Data based on the schema