rdfmapper
rdfmapper is a declarative Object-RDF Mapper for Python. It lets you map Python classes to RDF graphs using decorators — no SPARQL, no manual triple manipulation.
from rdfmapper import RDFMapper
mapper = RDFMapper()
@mapper.rdf_entity("http://xmlns.com/foaf/0.1/Person")
class Person:
def __init__(self, uri, name: str):
self.uri = uri
self._name = name
@mapper.rdf_property("http://xmlns.com/foaf/0.1/name", minCount=1)
def name(self): pass
person = Person("http://example.org/person/1", "Felipe")
graph = mapper.to_rdf(person)
print(graph.serialize(format="turtle"))
Features
- Declarative class-to-RDF mapping via decorators
- One-to-one and one-to-many relationships
- Automatic serialization and deserialization
- Dynamic query repository (
find_by_*,count_by_*,group_by_count) - Automatic SHACL shape generation and validation
- Circular reference safety
Installation
Origin
rdfmapper grew out of research at the LambdaGeo Group, Federal University of Maranhão (UFMA). See the Background page for the full story.