npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

rdflib-neo4j

v2.0.3

Published

RDFLib Store backed by neo4j, migrated to TypeScript

Readme

rdflib-neo4j

RDF Store backed by neo4j for TypeScript/JavaScript!

This library provides an RDF store implementation that persists RDF data to Neo4j, using the rdf.js ecosystem for RDF handling.

Migration Notice

This is a TypeScript/JavaScript migration of the original Python rdflib-neo4j library developed by Neo4j Labs. The original Python implementation was created by Jesús Barrasa, Aleksandar Simeunovic, and Alfredo Rubin. This TypeScript version maintains the same functionality and API design while using the rdf.js ecosystem instead of Python RDFLib.

Getting Started

Below are the procedures you should adhere to for both your Neo4j database and your TypeScript/JavaScript code:

On the Neo4j side

To configure your Neo4j Graph DB, the process is simplified: initialize the database by establishing a uniqueness constraint on Resources' URIs. You can achieve this by executing the following Cypher fragment:

CREATE CONSTRAINT n10s_unique_uri FOR (r:Resource) REQUIRE r.uri IS UNIQUE;

This constraint ensures the uniqueness of URIs for Resource nodes, streamlining the integration process. Alternatively, you can simply set create=true when attempting to open the store in your TypeScript code, and it will create the constraint for you.

On the TypeScript/JavaScript side

rdflib-neo4j can be installed with npm or yarn:

$ npm install rdflib-neo4j
# or
$ yarn add rdflib-neo4j

You're ready to go!

Now, seamlessly import RDF data into your Neo4j On-premise or Aura instance by establishing a store and parsing your RDF data. Each individual triple undergoes transparent persistence within your Neo4j database (whether it is on Aura or on-premise). Here's a step-by-step guide to achieve this integration:

You can import the data from an RDF document (for example this one serialised using N-Triples):

import { Neo4jStoreConfig, Neo4jStore, HANDLE_VOCAB_URI_STRATEGY } from 'rdflib-neo4j';
import { Parser } from 'n3';
import { DataFactory } from '@rdfjs/data-model';

// set the configuration to connect to your Aura DB
const AURA_DB_URI = "your_db_uri";
const AURA_DB_USERNAME = "neo4j";
const AURA_DB_PWD = "your_db_pwd";

const auth_data = {
  uri: AURA_DB_URI,
  database: "neo4j",
  user: AURA_DB_USERNAME,
  pwd: AURA_DB_PWD
};

// Define your custom prefixes
const prefixes = {
  'skos': 'http://www.w3.org/2004/02/skos/core#',
  'rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
};

// Define your custom mappings & store config
const config = new Neo4jStoreConfig(
  auth_data,
  [], // custom_mappings
  prefixes,
  true, // batching
  5000, // batch_size
  HANDLE_VOCAB_URI_STRATEGY.IGNORE
);

const file_path = 'https://github.com/jbarrasa/gc-2022/raw/main/search/onto/concept-scheme-skos.ttl';

// Create the RDF Store, parse & ingest the data to Neo4j, and close the store
// (If the field batching is set to true in the Neo4jStoreConfig, remember to close the store to prevent the loss of any uncommitted records.)
const neo4j_aura = new Neo4jStore(config);
await neo4j_aura.open(true);

// Fetch and parse the RDF file
const response = await fetch(file_path);
const rdfData = await response.text();
const parser = new Parser({ format: 'text/turtle' });
const quads = parser.parse(rdfData);

// Add all quads to the store
for (const quad of quads) {
  await neo4j_aura.add(quad);
}

await neo4j_aura.close(true);

The imported file contains a taxonomy of technologies extracted from Wikidata and serialised using SKOS. After running the previous code fragment, your Aura DB/Neo4j DB should be populated with a graph like this one:

You can also write to the graph triple by triple like this:

import { Neo4jStoreConfig, Neo4jStore, HANDLE_VOCAB_URI_STRATEGY } from 'rdflib-neo4j';
import { DataFactory } from '@rdfjs/data-model';

// Set up your store config
const config = new Neo4jStoreConfig(
  auth_data,
  [],
  {},
  false, // batching
  5000,
  HANDLE_VOCAB_URI_STRATEGY.IGNORE
);

// Create the graph and open the store
const neo4j_aura = new Neo4jStore(config);
await neo4j_aura.open(true);

// Define namespaces
const RDF = {
  type: DataFactory.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type')
};

const SKOS = {
  Concept: DataFactory.namedNode('http://www.w3.org/2004/02/skos/core#Concept'),
  prefLabel: DataFactory.namedNode('http://www.w3.org/2004/02/skos/core#prefLabel'),
  broader: DataFactory.namedNode('http://www.w3.org/2004/02/skos/core#broader')
};

const aura = DataFactory.namedNode("http://neo4j.com/voc/tech#AuraDB");
const neo4j = DataFactory.namedNode("http://www.wikidata.org/entity/Q1628290");

await neo4j_aura.add(DataFactory.quad(aura, RDF.type, SKOS.Concept));
await neo4j_aura.add(DataFactory.quad(aura, SKOS.prefLabel, DataFactory.literal("AuraDB")));
await neo4j_aura.add(DataFactory.quad(aura, SKOS.broader, neo4j));

await neo4j_aura.commit();
await neo4j_aura.close(true);

The previous fragment would add another node to the graph representing AuraDB as a concept related to Neo4j via skos:broader, which in your AuraDB graph would look as follows:

Requirements

  • Node.js 16+ or TypeScript 4.5+
  • Neo4j 5.0+ (with n10s plugin for full compatibility)

License

Apache 2.0