# rdflib

> an RDF library for node.js. Suitable for client and server side.

Latest version **2.4.0** (published 2026-06-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install rdflib
pnpm add rdflib
yarn add rdflib
bun add rdflib
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.4.0 |
| Published | 2026-06-24 |
| First published | 2013-08-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 10 |
| Unpacked size | 3.4 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 597 |
| Author | Tim BL |
| Maintainers | codenamedmitri, rubenverborgh, nicola, michielbdejong, megoth, timbl, jaxoncreed, ericprud, melvincarvalho, vincenttunru, bourgeoa, inrupt_ci, matthieubosquet, jeswr, timeaturdean |
| Keywords | linkeddata, linked data, rdf, rdfa, turtle, semantic, web, read-write web |

## Links

- npm: https://www.npmjs.com/package/rdflib
- Repository: https://github.com/linkeddata/rdflib.js
- Homepage: http://github.com/linkeddata/rdflib.js
- Issues: http://github.com/linkeddata/rdflib.js/issues
- npm.io page: https://npm.io/package/rdflib

## Dependencies (10)

- [n3](https://npm.io/package/n3.md) ^2.0.3
- [jsonld](https://npm.io/package/jsonld.md) ^9.0.0
- [cross-fetch](https://npm.io/package/cross-fetch.md) ^4.1.0
- [@rdfjs/types](https://npm.io/package/@rdfjs/types.md) ^2.0.1
- [package.json](https://npm.io/package/package.json.md) ^2.0.1
- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.29.2
- [@xmldom/xmldom](https://npm.io/package/@xmldom/xmldom.md) ^0.9.10
- [solid-namespace](https://npm.io/package/solid-namespace.md) ^0.5.4
- [package-lock.json](https://npm.io/package/package-lock.json.md) ^1.0.0
- [@frogcat/ttl2jsonld](https://npm.io/package/@frogcat/ttl2jsonld.md) ^0.0.10

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 2.4.0 (latest) — 2026-06-24
- 2.3.5-234a4299 (main) — 2026-03-16
- 2.3.6-alpha.0 (dev) — 2026-03-14
- 2.3.5-35888585 (774-merge) — 2026-03-14
- 2.3.5-fb951614 (770-merge) — 2026-03-13
- 2.3.5-073d6985 (758-merge) — 2026-01-15
- 2.3.5-9da1585b (756-merge) — 2026-01-15
- 2.3.5-4426f141 (748-merge) — 2026-01-05
- 2.3.3-2cbb77a1 (746-merge) — 2026-01-04
- 2.3.2-2bc27df4 (734-merge) — 2025-12-13
- 2.3.1-5f933d36 (733-merge) — 2025-12-12
- 2.3.1-0007ffed (732-merge) — 2025-12-11
- 2.3.0-9b8b541f (731-merge) — 2025-12-10
- 2.3.0-c8138d2c (718-merge) — 2025-12-10
- 2.3.0-9d362fae (721-merge) — 2025-11-05
- … 375 more at https://npm.io/package/rdflib/versions

## README

# rdflib.js
[![NPM Version](https://img.shields.io/npm/v/rdflib.svg?style=flat)](https://npm.im/rdflib)
[![Join the chat at https://gitter.im/linkeddata/rdflib.js](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/linkeddata/rdflib.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

Javascript RDF library for browsers and Node.js.

- Reads and writes RDF/XML, Turtle and N3; Reads RDFa and JSON-LD
- Read/Write Linked Data client, using WebDav or SPARQL/Update
- Real-Time Collaborative editing with web sockets and PATCHes
- Local API for querying a store
- Compatible with [RDFJS task force spec](https://github.com/rdfjs/representation-task-force/blob/master/interface-spec.md)
- SPARQL queries (not full SPARQL - just graph match and optional)
- Smushing of nodes from `owl:sameAs`, and `owl:{f,inverseF}unctionProperty`
- Tracks provenance of triples keeps metadata (in RDF) from HTTP accesses

## Documentation

See:

* The [API documentation](https://linkeddata.github.io/rdflib.js/doc/) is partial but useful
* [Tutorial: Using rdflib in a Solid web app](https://linkeddata.github.io/rdflib.js/Documentation/webapp-intro.html)
* [Tutorial: Using rdflib.js](https://github.com/solidos/solid-tutorial-rdflib.js)
* [Tutorial: Using Turtle](https://linkeddata.github.io/rdflib.js/Documentation/turtle-intro.html)
* [Using authenticated & alternate fetch methods](https://linkeddata.github.io/rdflib.js/Documentation/alternate-fetches.md)
* [Block diagram: rdflib modules](https://linkeddata.github.io/rdflib.js/Documentation/diagrams/rdflib-block-diagram.svg)
* [Block diagram: The Fetcher](https://linkeddata.github.io/rdflib.js/Documentation/diagrams/fetcher-block-diagram.svg)
* [Block diagram: The Fetcher - handling retries](https://linkeddata.github.io/rdflib.js/Documentation/diagrams/fetcher-block-diagram-2.svg)
* [Block diagram: The Update Manager](https://linkeddata.github.io/rdflib.js/Documentation/diagrams/update-manager-diagram.svg)


* [The Solid developer portal at Inrupt](https://solid.inrupt.com/)

for more information.

## Install

#### Browser (using a bundler like Webpack)

```bash
npm install rdflib
```

#### Browser (generating a `<script>` file to include)

```bash
git clone git@github.com:linkeddata/rdflib.js.git;
cd rdflib.js;
npm install;
```

Generate the dist directory

```bash
npm run build:browser
```

#### Node.js

Make sure you have Node.js and Node Package Manager ([npm](https://npmjs.org/))
installed.

```bash
npm install --save rdflib
```

## Serializer flags

The Turtle/N3/JSON‑LD serializers accept an optional `flags` string to tweak output formatting and abbreviation behavior.

- Pass flags via the options argument to `serialize(...)`:

```ts
import { graph, serialize, sym } from 'rdflib'

const kb = graph()
const doc = sym('http://example.com/doc')
// ... add some statements ...

// Example: prevent dotted local parts in prefixed names
const turtle = serialize(doc, kb, doc.value, 'text/turtle', undefined, { flags: 'o' })
```

Common flags used internally (you can combine them, e.g. `'o k'`):

- `s` `i` – used by default for Turtle to suppress `=`, `=>` notations
- `d e i n p r s t u x` – used for N-Triples/N-Quads to simplify output
- `dr` – used with JSON‑LD conversion (no default, no relative prefix)
- `o` – new: do not abbreviate to a prefixed name when the local part contains a dot. This keeps IRIs like
  `http://example.org/ns/subject.example` in `<...>` form instead of `ns:subject.example`.

Notes:

- For Turtle and JSON‑LD, user‑provided flags are merged with the defaults so your flags (like `o`) are honored.
- By contrast, passing `'p'` disables prefix abbreviations entirely (all terms are written as `<...>` IRIs).

## Contribute

#### Subdirectories

- `dist`: Where the bundled libraries are built. Run `npm run build` to generate them.
- `test`: Tests are here.
- `lib`: Transpiled, non-bundled library is built here when the library is
  published to npm.

#### Dependencies

    - XMLHTTPRequest (Node.js version)

## Thanks

Thanks to the many contributors who have been involved along the way.
LinkedData team & TimBL

## LICENSE
MIT

---
_Source: https://npm.io/package/rdflib · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
