From 61a2abdbfd021c5ae959c3cddee865cbfa1f98eb Mon Sep 17 00:00:00 2001 From: Florian Ludwig Date: Fri, 11 Sep 2020 22:01:58 +0200 Subject: fix Graph.serialize doc --- rdflib/graph.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/rdflib/graph.py b/rdflib/graph.py index b641656d..f6024c46 100644 --- a/rdflib/graph.py +++ b/rdflib/graph.py @@ -1,3 +1,4 @@ +from typing import Optional import logging from warnings import warn import random @@ -957,11 +958,11 @@ class Graph(Node): def serialize( self, destination=None, format="xml", base=None, encoding=None, **args - ): + ) -> Optional[bytes]: """Serialize the Graph to destination - If destination is None serialize method returns the serialization as a - string. Format defaults to xml (AKA rdf/xml). + If destination is None serialize method returns the serialization as + bytes. Format defaults to xml (AKA rdf/xml). Format support can be extended with plugins, but "xml", "n3", "turtle", "nt", "pretty-xml", "trix", "trig" and "nquads" are built in. -- cgit v1.2.1 From c589e762293f3c597a8b671df74c7ef703401efa Mon Sep 17 00:00:00 2001 From: Florian Ludwig Date: Fri, 11 Sep 2020 22:16:29 +0200 Subject: Loading and saving RDF docs only cover loading --- docs/intro_to_parsing.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/intro_to_parsing.rst b/docs/intro_to_parsing.rst index b07b3609..5b50e5ba 100644 --- a/docs/intro_to_parsing.rst +++ b/docs/intro_to_parsing.rst @@ -67,3 +67,15 @@ files you'll find on the net. RDFLib will also happily read RDF from any file-like object, i.e. anything with a ``.read()`` method. + + +Saving RDF +---------- + +To store a graph in a file use the :func:`rdflib.Graph.serialize` function: + +.. code-block:: python + + g.parse("http://bigasterisk.com/foaf.rdf") + with open("foaf.n3", "wb") as f: + g.serialize(f, format="n3") \ No newline at end of file -- cgit v1.2.1