Currently, the “nt” output format uses the most efficient serialization; “rdf/xml” should also be efficient. You can serialize to these formats using code similar to the following:
myGraph.serialize(target_nt, format="nt")
myGraph.serialize(target_rdfxml, format="xml")
Use the “pretty-xml” format argument to the serialize method:
myGraph.serialize(target_pretty, format="pretty-xml")
Each graph comes with a NamespaceManager instance in the namespace_manager field; you can use the bind method of this instance to bind a prefix to a namespace URI:
myGraph.namespace_manager.bind('prefix', URIRef('scheme:my-namespace-uri:'))