Skip to content

# `` namespace

## Namespace Utilities

RDFLib provides mechanisms for managing Namespaces.

In particular, there is a `Namespace` class that takes as its argument the base URI of the namespace.

    >>> from rdflib.namespace import Namespace
    >>> RDFS = Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#")

Fully qualified URIs in the namespace can be constructed either by attribute or by dictionary access on Namespace instances:

    >>> RDFS.seeAlso
    rdflib.term.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#seeAlso')
    >>> RDFS['seeAlso']
    rdflib.term.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#seeAlso')

### Automatic handling of unknown predicates

As a programming convenience, a namespace binding is automatically created when `URIRef` predicates are added to the graph.

### Importable namespaces

The following namespaces are available by directly importing from rdflib:

- BRICK
- CSVW
- DC
- DCAT
- DCMITYPE
- DCTERMS
- DCAM
- DOAP
- FOAF
- ODRL2
- ORG
- OWL
- PROF
- PROV
- QB
- RDF
- RDFS
- SDO
- SH
- SKOS
- SOSA
- SSN
- TIME
- VANN
- VOID
- WGS
- XSD

    >>> from rdflib.namespace import RDFS
    >>> RDFS.seeAlso
    rdflib.term.URIRef('http://www.w3.org/2000/01/rdf-schema#seeAlso')

Classes:

- `BRICK` –

  Brick Ontology classes, properties and entity properties. See https://brickschema.org/

- `CSVW` –

  CSVW Namespace Vocabulary Terms

- `ClosedNamespace` –

  A namespace with a closed list of members

- `DC` –

  Dublin Core Metadata Element Set, Version 1.1

- `DCAM` –

  Metadata terms for vocabulary description

- `DCAT` –

  The data catalog vocabulary

- `DCMITYPE` –

  DCMI Type Vocabulary

- `DCTERMS` –

  DCMI Metadata Terms - other

- `DOAP` –

  Description of a Project (DOAP) vocabulary

- `DefinedNamespace` –

  A Namespace with an enumerated list of members.

- `FOAF` –

  Friend of a Friend (FOAF) vocabulary

- `GEO` –

  An RDF/OWL vocabulary for representing spatial information

- `Namespace` –

  Utility class for quickly generating URIRefs with a common prefix.

- `NamespaceManager` –

  Class for managing prefix => namespace mappings

- `ODRL2` –

  ODRL Version 2.2

- `ORG` –

  Core organization ontology

- `OWL` –

  The OWL 2 Schema vocabulary (OWL 2)

- `PROF` –

  Profiles Vocabulary

- `PROV` –

  W3C PROVenance Interchange Ontology (PROV-O)

- `QB` –

  Vocabulary for multi-dimensional (e.g. statistical) data publishing

- `RDF` –

  The RDF Concepts Vocabulary (RDF)

- `RDFS` –

  The RDF Schema vocabulary (RDFS)

- `SDO` –

  schema.org namespace elements

- `SH` –

  W3C Shapes Constraint Language (SHACL) Vocabulary

- `SKOS` –

  SKOS Vocabulary

- `SOSA` –

  Sensor, Observation, Sample, and Actuator (SOSA) Ontology

- `SSN` –

  Semantic Sensor Network Ontology

- `TIME` –

  OWL-Time

- `VANN` –

  VANN: A vocabulary for annotating vocabulary descriptions

- `VOID` –

  Vocabulary of Interlinked Datasets (VoID)

- `WGS` –

  Basic Geo (WGS84 lat/long) Vocabulary

- `XSD` –

  W3C XML Schema Definition Language (XSD) 1.1 Part 2: Datatypes

## `` BRICK

    BRICK()

Bases: `DefinedNamespace`

Brick Ontology classes, properties and entity properties. See https://brickschema.org/ for more information.

Generated from: https://github.com/BrickSchema/Brick/releases/download/nightly/Brick.ttl Date: 2021-09-22T14:32:56

## `` CSVW

    CSVW()

Bases: `DefinedNamespace`

CSVW Namespace Vocabulary Terms

This document describes the RDFS vocabulary description used in the Metadata Vocabulary for Tabular Data [[tabular-metadata]] along with the default JSON-LD Context.

Generated from: http://www.w3.org/ns/csvw Date: 2020-05-26 14:19:58.184766

## `` ClosedNamespace

Bases: `Namespace`

A namespace with a closed list of members

Trying to create terms not listed is an error

## `` DC

    DC()

Bases: `DefinedNamespace`

Dublin Core Metadata Element Set, Version 1.1

Generated from: https://www.dublincore.org/specifications/dublin-core/dcmi-terms/dublin_core_elements.ttl Date: 2020-05-26 14:19:58.671906

## `` DCAM

    DCAM()

Bases: `DefinedNamespace`

Metadata terms for vocabulary description

Generated from: https://www.dublincore.org/specifications/dublin-core/dcmi-terms/dublin_core_abstract_model.ttl Date: 2020-05-26 14:20:00.970966

## `` DCAT

    DCAT()

Bases: `DefinedNamespace`

The data catalog vocabulary

DCAT is an RDF vocabulary designed to facilitate interoperability between data catalogs published on the Web. By using DCAT to describe datasets in data catalogs, publishers increase discoverability and enable applications easily to consume metadata from multiple catalogs. It further enables decentralized publishing of catalogs and facilitates federated dataset search across sites. Aggregated DCAT metadata can serve as a manifest file to facilitate digital preservation. DCAT is defined at http://www.w3.org/TR/vocab-dcat/. Any variance between that normative document and this schema is an error in this schema.

Generated from: https://www.w3.org/ns/dcat2.ttl Date: 2020-05-26 14:19:59.985854

## `` DCMITYPE

    DCMITYPE()

Bases: `DefinedNamespace`

DCMI Type Vocabulary

Generated from: https://www.dublincore.org/specifications/dublin-core/dcmi-terms/dublin_core_type.ttl Date: 2020-05-26 14:19:59.084150

## `` DCTERMS

    DCTERMS()

Bases: `DefinedNamespace`

DCMI Metadata Terms - other

Generated from: https://www.dublincore.org/specifications/dublin-core/dcmi-terms/dublin_core_terms.ttl Date: 2020-05-26 14:20:00.590514

## `` DOAP

    DOAP()

Bases: `DefinedNamespace`

Description of a Project (DOAP) vocabulary

The Description of a Project (DOAP) vocabulary, described using W3C RDF Schema and the Web Ontology Language.

Generated from: http://usefulinc.com/ns/doap Date: 2024-08-01 13:03:22.175167

## `` DefinedNamespace

    DefinedNamespace()

A Namespace with an enumerated list of members.

Warnings are emitted if unknown members are referenced if _warn is True.

## `` DefinedNamespaceMeta

Bases: `type`

Utility metaclass for generating URIRefs with a common prefix.

Methods:

- `__contains__` –

  Determine whether a URI or an individual item belongs to this namespace

- `as_jsonld_context` –

  Returns this DefinedNamespace as a JSON-LD ‘context’ object

### `` __contains__

    __contains__(item: str) -> bool

Determine whether a URI or an individual item belongs to this namespace

### `` as_jsonld_context

    as_jsonld_context(pfx: str) -> dict

Returns this DefinedNamespace as a JSON-LD ‘context’ object

## `` FOAF

    FOAF()

Bases: `DefinedNamespace`

Friend of a Friend (FOAF) vocabulary

The Friend of a Friend (FOAF) RDF vocabulary, described using W3C RDF Schema and the Web Ontology Language.

Generated from: http://xmlns.com/foaf/spec/index.rdf Date: 2020-05-26 14:20:01.597998

## `` GEO

    GEO()

Bases: `DefinedNamespace`

An RDF/OWL vocabulary for representing spatial information

Generated from: http://schemas.opengis.net/geosparql/1.0/geosparql_vocab_all.rdf Date: 2021-12-27 17:38:15.101187

    <http://www.opengis.net/ont/geosparql> dc:creator "Open Geospatial Consortium"^^xsd:string
    dc:date "2012-04-30"^^xsd:date
    dc:source <http://www.opengis.net/doc/IS/geosparql/1.0>
        "OGC GeoSPARQL – A Geographic Query Language for RDF Data OGC 11-052r5"^^xsd:string
    rdfs:seeAlso <http://www.opengis.net/def/function/ogc-geosparql/1.0>
        <http://www.opengis.net/def/rule/ogc-geosparql/1.0>
        <http://www.opengis.net/doc/IS/geosparql/1.0>
    owl:imports dc:
        <http://www.opengis.net/ont/gml>
        <http://www.opengis.net/ont/sf>
        <http://www.w3.org/2004/02/skos/core>
    owl:versionInfo "OGC GeoSPARQL 1.0"^^xsd:string

## `` Namespace

Bases: `str`

Utility class for quickly generating URIRefs with a common prefix.

    >>> from rdflib.namespace import Namespace
    >>> n = Namespace("http://example.org/")
    >>> n.Person # as attribute
    rdflib.term.URIRef('http://example.org/Person')
    >>> n['first-name'] # as item - for things that are not valid python identifiers
    rdflib.term.URIRef('http://example.org/first-name')
    >>> n.Person in n
    True
    >>> n2 = Namespace("http://example2.org/")
    >>> n.Person in n2
    False

Methods:

- `__contains__` –

  Allows to check if a URI is within (starts with) this Namespace.

### `` __contains__

    __contains__(ref: str) -> bool

Allows to check if a URI is within (starts with) this Namespace.

    >>> from rdflib import URIRef
    >>> namespace = Namespace('http://example.org/')
    >>> uri = URIRef('http://example.org/foo')
    >>> uri in namespace
    True
    >>> person_class = namespace['Person']
    >>> person_class in namespace
    True
    >>> obj = URIRef('http://not.example.org/bar')
    >>> obj in namespace
    False

## `` NamespaceManager

    NamespaceManager(graph: Graph, bind_namespaces: _NamespaceSetString = 'rdflib')

Class for managing prefix => namespace mappings

This class requires an RDFlib Graph as an input parameter and may optionally have the parameter bind_namespaces set. This second parameter selects a strategy which is one of the following:

- core:
  - binds several core RDF prefixes only
  - owl, rdf, rdfs, xsd, xml from the NAMESPACE_PREFIXES_CORE object
- rdflib:
  - binds all the namespaces shipped with RDFLib as DefinedNamespace instances
  - all the core namespaces and all the following: brick, csvw, dc, dcat
  - dcmitype, dcterms, dcam, doap, foaf, geo, odrl, org, prof, prov, qb, schema
  - sh, skos, sosa, ssn, time, vann, void
  - see the NAMESPACE_PREFIXES_RDFLIB object for the up-to-date list
  - this is default
- none:
  - binds no namespaces to prefixes
  - note this is NOT default behaviour
- cc:
  - using prefix bindings from prefix.cc which is a online prefixes database
  - not implemented yet - this is aspirational

Breaking changes

The namespaces bound for specific values of `bind_namespaces` constitute part of RDFLib’s public interface, so changes to them should only be additive within the same minor version. Removing values, or removing namespaces that are bound by default, constitutes a breaking change.

See the sample usage

    >>> import rdflib
    >>> from rdflib import Graph
    >>> from rdflib.namespace import Namespace, NamespaceManager
    >>> EX = Namespace('http://example.com/')
    >>> namespace_manager = NamespaceManager(Graph())
    >>> namespace_manager.bind('ex', EX, override=False)
    >>> g = Graph()
    >>> g.namespace_manager = namespace_manager
    >>> all_ns = [n for n in g.namespace_manager.namespaces()]
    >>> assert ('ex', rdflib.term.URIRef('http://example.com/')) in all_ns

Methods:

- `bind` –

  Bind a given namespace to the prefix

- `curie` –

  From a URI, generate a valid CURIE.

- `expand_curie` –

  Expand a CURIE of the form , e.g. “rdf:type”

- `normalizeUri` –

  Takes an RDF Term and ‘normalizes’ it into a QName (using the

### `` bind

    bind(prefix: Optional[str], namespace: Any, override: bool = True, replace: bool = False) -> None

Bind a given namespace to the prefix

If override, rebind, even if the given namespace is already bound to another prefix.

If replace, replace any existing prefix with the new namespace

### `` curie

    curie(uri: str, generate: bool = True) -> str

From a URI, generate a valid CURIE.

Result is guaranteed to contain a colon separating the prefix from the name, even if the prefix is an empty string.

Side-effect

When `generate` is `True` (which is the default) and there is no matching namespace for the URI in the namespace manager then a new namespace will be added with prefix `ns{index}`.

Thus, when `generate` is `True`, this function is not a pure function because of this side-effect.

This default behaviour is chosen so that this function operates similarly to `NamespaceManager.qname`.

Parameters:

- #### `uri`

  (`str`) –

  URI to generate CURIE for.

- #### `generate`

  (`bool`, default: `True` ) –

  Whether to add a prefix for the namespace if one doesn’t already exist. Default: `True`.

Returns:

- `str` –

  CURIE for the URI

Raises:

- `KeyError` –

  If generate is `False` and the namespace doesn’t already have a prefix.

### `` expand_curie

    expand_curie(curie: str) -> URIRef

Expand a CURIE of the form , e.g. “rdf:type” into its full expression:

> > > import rdflib g = rdflib.Graph() g.namespace_manager.expand_curie(“rdf:type”) rdflib.term.URIRef(‘http://www.w3.org/1999/02/22-rdf-syntax-ns#type’)

Raises exception if a namespace is not bound to the prefix.

### `` normalizeUri

    normalizeUri(rdfTerm: str) -> str

Takes an RDF Term and ‘normalizes’ it into a QName (using the registered prefix) or (unlike compute_qname) the Notation 3 form for URIs: <…URI…>

## `` ODRL2

    ODRL2()

Bases: `DefinedNamespace`

ODRL Version 2.2

The ODRL Vocabulary and Expression defines a set of concepts and terms (the vocabulary) and encoding mechanism (the expression) for permissions and obligations statements describing digital content usage based on the ODRL Information Model.

Generated from: https://www.w3.org/ns/odrl/2/ODRL22.ttl Date: 2020-05-26 14:20:02.352356

## `` ORG

    ORG()

Bases: `DefinedNamespace`

Core organization ontology

Vocabulary for describing organizational structures, specializable to a broad variety of types of organization.

Generated from: http://www.w3.org/ns/org# Date: 2020-05-26 14:20:02.908408

## `` OWL

    OWL()

Bases: `DefinedNamespace`

The OWL 2 Schema vocabulary (OWL 2)

This ontology partially describes the built-in classes and properties that together form the basis of the RDF/XML syntax of OWL 2. The content of this ontology is based on Tables 6.1 and 6.2 in Section 6.4 of the OWL 2 RDF-Based Semantics specification, available at http://www.w3.org/TR/owl2-rdf-based- semantics/. Please note that those tables do not include the different annotations (labels, comments and rdfs:isDefinedBy links) used in this file. Also note that the descriptions provided in this ontology do not provide a complete and correct formal description of either the syntax or the semantics of the introduced terms (please see the OWL 2 recommendations for the complete and normative specifications). Furthermore, the information provided by this ontology may be misleading if not used with care. This ontology SHOULD NOT be imported into OWL ontologies. Importing this file into an OWL 2 DL ontology will cause it to become an OWL 2 Full ontology and may have other, unexpected, consequences.

Generated from: http://www.w3.org/2002/07/owl# Date: 2020-05-26 14:20:03.193795

## `` PROF

    PROF()

Bases: `DefinedNamespace`

Profiles Vocabulary

This vocabulary is for describing relationships between standards/specifications, profiles of them and supporting artifacts such as validating resources. This model starts with http://dublincore.org/2012/06/14/dcterms#Standard entities which can either be Base Specifications (a standard not profiling any other Standard) or Profiles (Standards which do profile others). Base Specifications or Profiles can have Resource Descriptors associated with them that defines implementing rules for the it. Resource Descriptors must indicate the role they play (to guide, to validate etc.) and the formalism they adhere to (dct:format) to allow for content negotiation. A vocabulary of Resource Roles are provided alongside this vocabulary but that list is extensible.

Generated from: https://www.w3.org/ns/dx/prof/profilesont.ttl Date: 2020-05-26 14:20:03.542924

## `` PROV

    PROV()

Bases: `DefinedNamespace`

W3C PROVenance Interchange Ontology (PROV-O)

This document is published by the Provenance Working Group (http://www.w3.org/2011/prov/wiki/Main_Page). If you wish to make comments regarding this document, please send them to public-prov-comments@w3.org (subscribe public-prov-comments-request@w3.org, archives http://lists.w3.org/Archives/Public/public-prov-comments/). All feedback is welcome.

PROV Access and Query Ontology

This document is published by the Provenance Working Group (http://www.w3.org/2011/prov/wiki/Main_Page). If you wish to make comments regarding this document, please send them to public-prov-comments@w3.org (subscribe public-prov-comments-request@w3.org, archives http://lists.w3.org/Archives/Public/public-prov-comments/). All feedback is welcome.

Dublin Core extensions of the W3C PROVenance Interchange Ontology (PROV-O)

This document is published by the Provenance Working Group (http://www.w3.org/2011/prov/wiki/Main_Page). If you wish to make comments regarding this document, please send them to public-prov-comments@w3.org (subscribe public-prov-comments-request@w3.org, archives http://lists.w3.org/Archives/Public/public-prov-comments/). All feedback is welcome.

W3C PROV Linking Across Provenance Bundles Ontology (PROV-LINKS)

This document is published by the Provenance Working Group (http://www.w3.org/2011/prov/wiki/Main_Page). If you wish to make comments regarding this document, please send them to public-prov-comments@w3.org (subscribe public-prov-comments-request@w3.org, archives http://lists.w3.org/Archives/Public/public-prov-comments/ ). All feedback is welcome.

W3C PROVenance Interchange Ontology (PROV-O) Dictionary Extension

This document is published by the Provenance Working Group (http://www.w3.org/2011/prov/wiki/Main_Page). If you wish to make comments regarding this document, please send them to public-prov-comments@w3.org (subscribe public-prov-comments-request@w3.org, archives http://lists.w3.org/Archives/Public/public-prov- comments/). All feedback is welcome.

W3C PROVenance Interchange

This document is published by the Provenance Working Group (http://www.w3.org/2011/prov/wiki/Main_Page). If you wish to make comments regarding this document, please send them to public-prov-comments@w3.org (subscribe public-prov-comments-request@w3.org, archives http://lists.w3.org/ Archives/Public/public-prov-comments/). All feedback is welcome.

Generated from: http://www.w3.org/ns/prov Date: 2020-05-26 14:20:04.650279

## `` QB

    QB()

Bases: `DefinedNamespace`

Vocabulary for multi-dimensional (e.g. statistical) data publishing

This vocabulary allows multi-dimensional data, such as statistics, to be published in RDF. It is based on the core information model from SDMX (and thus also DDI).

Generated from: http://purl.org/linked-data/cube# Date: 2020-05-26 14:20:05.485176

## `` RDF

    RDF()

Bases: `DefinedNamespace`

The RDF Concepts Vocabulary (RDF)

This is the RDF Schema for the RDF vocabulary terms in the RDF Namespace, defined in RDF 1.1 Concepts.

Generated from: http://www.w3.org/1999/02/22-rdf-syntax-ns# Date: 2020-05-26 14:20:05.642859

dc:date “2019-12-16”

## `` RDFS

    RDFS()

Bases: `DefinedNamespace`

The RDF Schema vocabulary (RDFS)

Generated from: http://www.w3.org/2000/01/rdf-schema# Date: 2020-05-26 14:20:05.794866

## `` SDO

    SDO()

Bases: `DefinedNamespace`

schema.org namespace elements

3DModel, True, False & yield are not available as they collde with Python terms

Generated from: https://schema.org/version/latest/schemaorg-current-https.jsonld Date: 2021-12-01 By: Nicholas J. Car

## `` SH

    SH()

Bases: `DefinedNamespace`

W3C Shapes Constraint Language (SHACL) Vocabulary

This vocabulary defines terms used in SHACL, the W3C Shapes Constraint Language.

Generated from: https://www.w3.org/ns/shacl.ttl Date: 2020-05-26 14:20:08.041103

## `` SKOS

    SKOS()

Bases: `DefinedNamespace`

SKOS Vocabulary

An RDF vocabulary for describing the basic structure and content of concept schemes such as thesauri, classification schemes, subject heading lists, taxonomies, ‘folksonomies’, other types of controlled vocabulary, and also concept schemes embedded in glossaries and terminologies.

Generated from: https://www.w3.org/2009/08/skos-reference/skos.rdf Date: 2020-05-26 14:20:08.489187

## `` SOSA

    SOSA()

Bases: `DefinedNamespace`

Sensor, Observation, Sample, and Actuator (SOSA) Ontology

This ontology is based on the SSN Ontology by the W3C Semantic Sensor Networks Incubator Group (SSN-XG), together with considerations from the W3C/OGC Spatial Data on the Web Working Group.

Generated from: http://www.w3.org/ns/sosa/ Date: 2020-05-26 14:20:08.792504

## `` SSN

    SSN()

Bases: `DefinedNamespace`

Semantic Sensor Network Ontology

This ontology describes sensors, actuators and observations, and related concepts. It does not describe domain concepts, time, locations, etc. these are intended to be included from other ontologies via OWL imports.

Generated from: http://www.w3.org/ns/ssn/ Date: 2020-05-26 14:20:09.068204

## `` TIME

    TIME()

Bases: `DefinedNamespace`

OWL-Time

Generated from: http://www.w3.org/2006/time# Date: 2020-05-26 14:20:10.531265

## `` URIPattern

Bases: `str`

Utility class for creating URIs according to some pattern.

This supports either new style formatting with .format or old-style with % operator.

    >>> u=URIPattern("http://example.org/%s/%d/resource")
    >>> u%('books', 12345)
    rdflib.term.URIRef('http://example.org/books/12345/resource')

## `` VANN

    VANN()

Bases: `DefinedNamespace`

VANN: A vocabulary for annotating vocabulary descriptions

This document describes a vocabulary for annotating descriptions of vocabularies with examples and usage notes.

Generated from: https://vocab.org/vann/vann-vocab-20100607.rdf Date: 2020-05-26 14:21:15.580430

## `` VOID

    VOID()

Bases: `DefinedNamespace`

Vocabulary of Interlinked Datasets (VoID)

The Vocabulary of Interlinked Datasets (VoID) is an RDF Schema vocabulary for expressing metadata about RDF datasets. It is intended as a bridge between the publishers and users of RDF data, with applications ranging from data discovery to cataloging and archiving of datasets. This document provides a formal definition of the new RDF classes and properties introduced for VoID. It is a companion to the main specification document for VoID, Describing Linked Datasets with the VoID Vocabulary.

Generated from: http://rdfs.org/ns/void# Date: 2020-05-26 14:20:11.911298

## `` WGS

    WGS()

Bases: `DefinedNamespace`

Basic Geo (WGS84 lat/long) Vocabulary

The HTML Specification for the vocabulary can be found here https://www.w3.org/2003/01/geo/.

## `` XSD

    XSD()

Bases: `DefinedNamespace`

W3C XML Schema Definition Language (XSD) 1.1 Part 2: Datatypes

Generated from: ../schemas/datatypes.xsd Date: 2021-09-05 20:37+10

## `` insert_trie

    insert_trie(trie: Dict[str, Any], value: str) -> Dict[str, Any]

Insert a value into the trie if it is not already contained in the trie. Return the subtree for the value regardless of whether it is a new value or not.