rdflib.plugins.serializers package

Submodules

rdflib.plugins.serializers.jsonld module

This serialiser will output an RDF Graph as a JSON-LD formatted document. See:

Example usage:

>>> from rdflib import Graph
>>> testrdf = '''
... @prefix dc: <http://purl.org/dc/terms/> .
... <http://example.org/about>
...     dc:title "Someone's Homepage"@en .
... '''

>>> g = Graph().parse(data=testrdf, format='n3')

>>> print(g.serialize(format='json-ld', indent=4))
[
    {
        "@id": "http://example.org/about",
        "http://purl.org/dc/terms/title": [
            {
                "@language": "en",
                "@value": "Someone's Homepage"
            }
        ]
    }
]
class rdflib.plugins.serializers.jsonld.JsonLDSerializer(store)[source]

Bases: rdflib.serializer.Serializer

__init__(store)[source]
__module__ = 'rdflib.plugins.serializers.jsonld'
serialize(stream, base=None, encoding=None, **kwargs)[source]

Abstract method

rdflib.plugins.serializers.jsonld.from_rdf(graph, context_data=None, base=None, use_native_types=False, use_rdf_type=False, auto_compact=False, startnode=None, index=False)[source]

rdflib.plugins.serializers.n3 module

Notation 3 (N3) RDF graph serializer for RDFLib.

class rdflib.plugins.serializers.n3.N3Serializer(store, parent=None)[source]

Bases: rdflib.plugins.serializers.turtle.TurtleSerializer

__init__(store, parent=None)[source]
__module__ = 'rdflib.plugins.serializers.n3'
endDocument()[source]
getQName(uri, gen_prefix=True)[source]
indent(modifier=0)[source]

Returns indent string multiplied by the depth

isDone(subject)[source]

Return true if subject is serialized

p_clause(node, position)[source]
path(node, position, newline=False)[source]
preprocessTriple(triple)[source]
reset()[source]
s_clause(subject)[source]
short_name = 'n3'
startDocument()[source]
statement(subject)[source]
subjectDone(subject)[source]

Mark a subject as done.

rdflib.plugins.serializers.nquads module

class rdflib.plugins.serializers.nquads.NQuadsSerializer(store)[source]

Bases: rdflib.serializer.Serializer

__init__(store)[source]
__module__ = 'rdflib.plugins.serializers.nquads'
serialize(stream, base=None, encoding=None, **args)[source]

Abstract method

rdflib.plugins.serializers.nt module

N-Triples RDF graph serializer for RDFLib. See <http://www.w3.org/TR/rdf-testcases/#ntriples> for details about the format.

class rdflib.plugins.serializers.nt.NTSerializer(store)[source]

Bases: rdflib.serializer.Serializer

Serializes RDF graphs to NTriples format.

__init__(store)[source]
__module__ = 'rdflib.plugins.serializers.nt'
serialize(stream, base=None, encoding=None, **args)[source]

Abstract method

rdflib.plugins.serializers.rdfxml module

class rdflib.plugins.serializers.rdfxml.PrettyXMLSerializer(store, max_depth=3)[source]

Bases: rdflib.serializer.Serializer

__init__(store, max_depth=3)[source]
__module__ = 'rdflib.plugins.serializers.rdfxml'
predicate(predicate, object, depth=1)[source]
serialize(stream, base=None, encoding=None, **args)[source]

Abstract method

subject(subject, depth=1)[source]
class rdflib.plugins.serializers.rdfxml.XMLSerializer(store)[source]

Bases: rdflib.serializer.Serializer

__init__(store)[source]
__module__ = 'rdflib.plugins.serializers.rdfxml'
predicate(predicate, object, depth=1)[source]
serialize(stream, base=None, encoding=None, **args)[source]

Abstract method

subject(subject, depth=1)[source]
rdflib.plugins.serializers.rdfxml.fix(val)[source]

strip off _: from nodeIDs… as they are not valid NCNames

rdflib.plugins.serializers.trig module

Trig RDF graph serializer for RDFLib. See <http://www.w3.org/TR/trig/> for syntax specification.

class rdflib.plugins.serializers.trig.TrigSerializer(store)[source]

Bases: rdflib.plugins.serializers.turtle.TurtleSerializer

__init__(store)[source]
__module__ = 'rdflib.plugins.serializers.trig'
indentString = '    '
preprocess()[source]
reset()[source]
serialize(stream, base=None, encoding=None, spacious=None, **args)[source]

Abstract method

short_name = 'trig'

rdflib.plugins.serializers.trix module

class rdflib.plugins.serializers.trix.TriXSerializer(store)[source]

Bases: rdflib.serializer.Serializer

__init__(store)[source]
__module__ = 'rdflib.plugins.serializers.trix'
serialize(stream, base=None, encoding=None, **args)[source]

Abstract method

rdflib.plugins.serializers.turtle module

Turtle RDF graph serializer for RDFLib. See <http://www.w3.org/TeamSubmission/turtle/> for syntax specification.

class rdflib.plugins.serializers.turtle.RecursiveSerializer(store)[source]

Bases: rdflib.serializer.Serializer

__init__(store)[source]
__module__ = 'rdflib.plugins.serializers.turtle'
addNamespace(prefix, uri)[source]
buildPredicateHash(subject)[source]

Build a hash key by predicate to a list of objects for the given subject

checkSubject(subject)[source]

Check to see if the subject should be serialized yet

indent(modifier=0)[source]

Returns indent string multiplied by the depth

indentString = '  '
isDone(subject)[source]

Return true if subject is serialized

maxDepth = 10
orderSubjects()[source]
predicateOrder = [rdflib.term.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), rdflib.term.URIRef('http://www.w3.org/2000/01/rdf-schema#label')]
preprocess()[source]
preprocessTriple(spo)[source]
reset()[source]
roundtrip_prefixes = ()
sortProperties(properties)[source]

Take a hash from predicate uris to lists of values. Sort the lists of values. Return a sorted list of properties.

subjectDone(subject)[source]

Mark a subject as done.

topClasses = [rdflib.term.URIRef('http://www.w3.org/2000/01/rdf-schema#Class')]
write(text)[source]

Write text in given encoding.

class rdflib.plugins.serializers.turtle.TurtleSerializer(store)[source]

Bases: rdflib.plugins.serializers.turtle.RecursiveSerializer

__init__(store)[source]
__module__ = 'rdflib.plugins.serializers.turtle'
addNamespace(prefix, namespace)[source]
doList(l_)[source]
endDocument()[source]
getQName(uri, gen_prefix=True)[source]
indentString = '    '
isValidList(l_)[source]

Checks if l is a valid RDF list, i.e. no nodes have other properties.

label(node, position)[source]
objectList(objects)[source]
p_default(node, position, newline=False)[source]
p_squared(node, position, newline=False)[source]
path(node, position, newline=False)[source]
predicateList(subject, newline=False)[source]
preprocessTriple(triple)[source]
reset()[source]
s_default(subject)[source]
s_squared(subject)[source]
serialize(stream, base=None, encoding=None, spacious=None, **args)[source]

Abstract method

short_name = 'turtle'
startDocument()[source]
statement(subject)[source]
verb(node, newline=False)[source]

rdflib.plugins.serializers.xmlwriter module

class rdflib.plugins.serializers.xmlwriter.XMLWriter(stream, namespace_manager, encoding=None, decl=1, extra_ns=None)[source]

Bases: object

__dict__ = mappingproxy({'__module__': 'rdflib.plugins.serializers.xmlwriter', '__init__': <function XMLWriter.__init__>, '_XMLWriter__get_indent': <function XMLWriter.__get_indent>, 'indent': <property object>, '_XMLWriter__close_start_tag': <function XMLWriter.__close_start_tag>, 'push': <function XMLWriter.push>, 'pop': <function XMLWriter.pop>, 'element': <function XMLWriter.element>, 'namespaces': <function XMLWriter.namespaces>, 'attribute': <function XMLWriter.attribute>, 'text': <function XMLWriter.text>, 'qname': <function XMLWriter.qname>, '__dict__': <attribute '__dict__' of 'XMLWriter' objects>, '__weakref__': <attribute '__weakref__' of 'XMLWriter' objects>, '__doc__': None, '__annotations__': {}})
__init__(stream, namespace_manager, encoding=None, decl=1, extra_ns=None)[source]
__module__ = 'rdflib.plugins.serializers.xmlwriter'
__weakref__

list of weak references to the object (if defined)

attribute(uri, value)[source]
element(uri, content, attributes={})[source]

Utility method for adding a complete simple element

property indent
namespaces(namespaces=None)[source]
pop(uri=None)[source]
push(uri)[source]
qname(uri)[source]

Compute qname for a uri using our extra namespaces, or the given namespace manager

text(text)[source]

Module contents