Using SPIN one can parametrize a query and turn it into a web service. Or express business rules in SPARQL and execute them directly on any RDF data and models. Or define and share data quality constraints over the web.

These and many other features illustrate what we mean when we say “SPIN is SPARQL on steroids”. SPIN turns SPARQL into a complete and powerful application development tool.

Next generation of SPIN has now been standardized by W3C as SHACL. TopQuadrant will continue to support SPIN in foreseeable future. However, we recommend for new implementations to use SHACL which should be regarded as SPIN 2.0. Users of SPIN considering migration to SHACL should read From SPIN to SHACL.


What problem does SPIN address

SPIN helps users to leverage the fast performance and rich expressivity of SPARQL for various application purposes through:

  • Query Templates – reusable SPARQL queries with parameters, available as web services
  • Rules and Data Quality Constraints – very expressive, attached to classes in the model to drive business behavior.
  • Functions – new custom query elements defined in SPARQL or in languages such as JavaScript. Great way to simplify queries and re-use common query patterns.
  • RDF syntax for SPARQL – all SPIN elements are completely declarative and stored entirely in RDF. This means that query collection can be queried, shared and discovered using the same infrastructure that also holds the data.


  • Simpler, Faster, more Flexible Architecture – SPIN operates directly on RDF. Thus, there is no need to transform the data into another format in order to run rules.
  • Skills Reuse – Developers don’t need to learn one language for querying and another for rules
  • Robust and Future-proof – based on the standard SPARQL. Encourages re-use and modularity. Entirely model-driven.

Here are just a few of the application needs addressed by SPIN Rules and Constraints:

  • Dynamically calculate the value of a property based on other properties – for example, the area of a rectangle as a product of its height and width, the age of a person as a difference between today’s date and person’s birthday or a display name as a concatenation of the first and last names. In each case, a SPARQL query that performs the calculation is attached to a class Rectangle or a class Person.
  • Check constraints and perform data validation – for example, to automatically raise inconsistency flags when currently available information does not fit the specified integrity constraints. In TopBraid EVN this is used to implement data validity checks such as a concept cannot have more than one preferred label in English (or German, French or any other language).
  • Isolate a set of rules to be executed under certain conditions – for example, to support incremental reasoning, to initialize certain values when a resource is first created, or to drive interactive applications. Among many uses taking advantage of this capability is triggering email notification each time a change is made in an EVN vocabulary or ontology.

SPIN is part of the SPIN Technology Stack that also includes SPARQLMotion and SPARQL Web Pages (SWP).

Note that SPIN is also sometimes referred to as SPARQL Rules.

What is SPIN

SPIN describes object behavior on the web of data by combining concepts from object oriented languages, query languages, and rule-based systems. It includes the following components:

Parametrized Queries, Web Services SPIN Templates Rules and Constraints SPIN Rules, SPIN Constraints attached to ontology classes Custom Query Elements Re-usable SPIN Functions or “magic” properties typically implemented as SPARQL subqueries and sometimes as programs in JavaScript, Java, etc. RDF Representation RDF Syntax for SPARQL

SPIN queries are stored in RDF together with ontology models.

SPIN functions make it possible to re-use common SPARQL patterns. They simplify SPARQL queries and make them more maintainable.

A basic idea of SPIN is to link ontology classes with SPARQL queries that define constraints and rules formalizing the expected behavior of class members.

  • Rules are implemented using SPARQL CONSTRUCT or SPARQL UPDATE requests (INSERT and DELETE). They create (infer) new information based on existing data.
  • Constraints are specified using SPARQL ASK or CONSTRUCT queries. A common need in applications is to check validity of the data. For example, you may want to require that a field is entered and/or that the string entered follows your format requirements. SPIN offers a way to do constraint checking with closed world semantics and automatically raise inconsistency flags when currently available information does not fit the specified integrity constraints.

SPIN templates are parametrized queries that are available as RESTful web services. As functions, they also make it possible to re-use common SPARQL patterns.

How to use SPIN

An effective way to implement and test SPIN is to use TopBraid Composer (TBC).

TBC provides:

  • Convenient SPIN/SPARQL editors with syntax highlighting and auto-completion.
  • Wizards for building reusable SPARQL queries as SPIN templates and functions.
  • Built-in inference engine TopSPIN to execute SPIN rules.
  • Graphical SPINMap editor for using SPIN to creating executable mappings across models
  • Statistics view for understanding and tuning performance of SPIN rules.

After you develop your SPIN artifacts, they can be deployed to any of TopBraid server products such as TopBraid Live, TopBraid EVN and TopBraid Insight.

Java programmers can create and process SPIN models with the open source TopBraid SPIN API.

TopBraid includes pre-built SPIN templates for OWL 2 RL profile and for checking data quality constraints defined in the SKOS standard. Other SPIN libraries are becoming available from SPIN users.

Learn how to use SPIN

While you can begin developing applications by reading through the technical materials listed on this site and consulting the Help facility in TopBraid Composer, for best results we recommend taking TopBraid Platform and Tools training.

Application Examples

Specifications and Documentation

SPIN at the W3C

Using SPARQL and SPIN for Data Quality Management on the Semantic Web

SPIN in Action: Reshaping Relational Data using SPINMap