from rdflib import Graph, Namespace, URIRef
mns = Namespace("http://my-namespace.net/")
g = Graph(base="http://my-base.net/")
g.add((mns.foo, URIRef("http://my-base.net/my-predicate"), mns.bar))
print(g.serialize(format="text/turtle"))
Prints the following (with redundant ns1 prefix):
@base <http://my-base.net/> .
@prefix ns1: <http://my-base.net/> .
<http://my-namespace.net/foo> <my-predicate> <http://my-namespace.net/bar> .
While the expected output is:
@base <http://my-base.net/> .
<http://my-namespace.net/foo> <my-predicate> <http://my-namespace.net/bar> .