rdflib.plugins.serializers package¶
Submodules¶
rdflib.plugins.serializers.hext module¶
HextuplesSerializer RDF graph serializer for RDFLib. See <https://github.com/ontola/hextuples> for details about the format.
- class rdflib.plugins.serializers.hext.HextuplesSerializer(store)[source]¶
Bases:
Serializer
Serializes RDF graphs to NTriples format.
- Parameters:
store (
Union
[Graph
,Dataset
,ConjunctiveGraph
])
- __annotations__ = {'contexts': 'List[Union[Graph, IdentifiedNode]]', 'dumps': 'Callable'}¶
- __firstlineno__ = 28¶
- __module__ = 'rdflib.plugins.serializers.hext'¶
- __static_attributes__ = ('contexts', 'default_context', 'graph_type')¶
-
contexts:
List
[Union
[Graph
,IdentifiedNode
]]¶
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=2))
[
{
"@id": "http://example.org/about",
"http://purl.org/dc/terms/title": [
{
"@language": "en",
"@value": "Someone's Homepage"
}
]
}
]
rdflib.plugins.serializers.longturtle module¶
LongTurtle RDF graph serializer for RDFLib. See <http://www.w3.org/TeamSubmission/turtle/> for syntax specification.
This variant, longturtle as opposed to just turtle, makes some small format changes to turtle - the original turtle serializer. It:
uses PREFIX instead of @prefix
uses BASE instead of @base
adds a new line at RDF.type, or ‘a’
adds a newline and an indent for all triples with more than one object (object list)
- adds a new line and ‘;’ for the last triple in a set with ‘.’
on the start of the next line
uses default encoding (encode()) is used instead of “latin-1”
Nicholas Car, 2023
- class rdflib.plugins.serializers.longturtle.LongTurtleSerializer(store)[source]¶
Bases:
RecursiveSerializer
- __annotations__ = {}¶
- __firstlineno__ = 35¶
- __module__ = 'rdflib.plugins.serializers.longturtle'¶
- __static_attributes__ = ('_ns_rewrite', '_shortNames', '_spacious', '_started', 'base', 'keywords', 'stream')¶
- indentString = ' '¶
- short_name = 'longturtle'¶
rdflib.plugins.serializers.n3 module¶
Notation 3 (N3) RDF graph serializer for RDFLib.
rdflib.plugins.serializers.nquads module¶
rdflib.plugins.serializers.nt module¶
rdflib.plugins.serializers.patch module¶
- class rdflib.plugins.serializers.patch.PatchSerializer(store)[source]¶
Bases:
Serializer
Creates an RDF patch file to add and remove triples/quads. Can either: - Create an add or delete patch for a single Dataset. - Create a patch to represent the difference between two Datasets.
- Parameters:
store (
Dataset
)
- __annotations__ = {}¶
- __firstlineno__ = 15¶
- __module__ = 'rdflib.plugins.serializers.patch'¶
- __static_attributes__ = ('store',)¶
- serialize(stream, base=None, encoding=None, **kwargs)[source]¶
Serialize the store to the given stream. :type stream:
IO
[bytes
] :param stream: The stream to serialize to. :type base:Optional
[str
] :param base: The base URI to use for the serialization. :type encoding:Optional
[str
] :param encoding: The encoding to use for the serialization. :type kwargs: :param kwargs: Additional keyword arguments. Supported keyword arguments: - operation: The operation to perform. Either ‘add’ or ‘remove’. - target: The target Dataset to compare against. NB: Only one of ‘operation’ or ‘target’ should be provided. - header_id: The header ID to use. - header_prev: The previous header ID to use.
rdflib.plugins.serializers.rdfxml module¶
- class rdflib.plugins.serializers.rdfxml.PrettyXMLSerializer(store, max_depth=3)[source]¶
Bases:
Serializer
- Parameters:
store (
Graph
)
- __annotations__ = {}¶
- __firstlineno__ = 169¶
- __module__ = 'rdflib.plugins.serializers.rdfxml'¶
- __static_attributes__ = ('__serialized', 'base', 'forceRDFAbout', 'max_depth', 'nm', 'writer')¶
- predicate(predicate, object, depth=1)[source]¶
- Parameters:
predicate (
Identifier
)object (
Identifier
)depth (
int
)
- Return type:
- subject(subject, depth=1)[source]¶
- Parameters:
subject (
Identifier
)depth (
int
)
- class rdflib.plugins.serializers.rdfxml.XMLSerializer(store)[source]¶
Bases:
Serializer
- Parameters:
store (
Graph
)
- __annotations__ = {}¶
- __firstlineno__ = 21¶
- __module__ = 'rdflib.plugins.serializers.rdfxml'¶
- __static_attributes__ = ('__serialized', '__stream', 'base', 'write')¶
- predicate(predicate, object, depth=1)[source]¶
- Parameters:
predicate (
Identifier
)object (
Identifier
)depth (
int
)
- Return type:
- subject(subject, depth=1)[source]¶
- Parameters:
subject (
Identifier
)depth (
int
)
- Return type:
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:
TurtleSerializer
- Parameters:
store (
Union
[Graph
,ConjunctiveGraph
])
- __annotations__ = {}¶
- __firstlineno__ = 20¶
- __init__(store)[source]¶
- Parameters:
store (
Union
[Graph
,ConjunctiveGraph
])
- __module__ = 'rdflib.plugins.serializers.trig'¶
- __static_attributes__ = ('_contexts', '_serialized', '_spacious', '_subjects', 'base', 'contexts', 'default_context', 'store', 'stream')¶
- indentString = ' '¶
- short_name = 'trig'¶
rdflib.plugins.serializers.trix module¶
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:
Serializer
- Parameters:
store (
Graph
)
- __annotations__ = {'roundtrip_prefixes': 'Tuple[Any, ...]'}¶
- __firstlineno__ = 34¶
- __module__ = 'rdflib.plugins.serializers.turtle'¶
- __static_attributes__ = ('_references', '_serialized', '_subjects', '_topLevels', 'depth', 'lists', 'namespaces', 'stream')¶
- buildPredicateHash(subject)[source]¶
Build a hash key by predicate to a list of objects for the given subject
- indentString = ' '¶
- maxDepth = 10¶
- 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')]¶
- sortProperties(properties)[source]¶
Take a hash from predicate uris to lists of values. Sort the lists of values. Return a sorted list of properties.
- topClasses = [rdflib.term.URIRef('http://www.w3.org/2000/01/rdf-schema#Class')]¶
- class rdflib.plugins.serializers.turtle.TurtleSerializer(store)[source]¶
Bases:
RecursiveSerializer
- Parameters:
store (
Graph
)
- __annotations__ = {}¶
- __firstlineno__ = 181¶
- __module__ = 'rdflib.plugins.serializers.turtle'¶
- __static_attributes__ = ('_ns_rewrite', '_shortNames', '_spacious', '_started', 'base', 'keywords', 'stream')¶
- indentString = ' '¶
- short_name = 'turtle'¶
rdflib.plugins.serializers.xmlwriter module¶
- class rdflib.plugins.serializers.xmlwriter.XMLWriter(stream, namespace_manager, encoding=None, decl=1, extra_ns=None)[source]¶
Bases:
object
- Parameters:
- __dict__ = mappingproxy({'__module__': 'rdflib.plugins.serializers.xmlwriter', '__firstlineno__': 18, '__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>, '__static_attributes__': ('closed', 'element_stack', 'extra_ns', 'nm', 'parent', 'stream'), '__dict__': <attribute '__dict__' of 'XMLWriter' objects>, '__weakref__': <attribute '__weakref__' of 'XMLWriter' objects>, '__doc__': None, '__annotations__': {'element_stack': 'List[str]'}})¶
- __firstlineno__ = 18¶
- __module__ = 'rdflib.plugins.serializers.xmlwriter'¶
- __static_attributes__ = ('closed', 'element_stack', 'extra_ns', 'nm', 'parent', 'stream')¶
- __weakref__¶
list of weak references to the object