# rdflib.tools package

## Submodules

## rdflib.tools.chunk_serializer module

This file provides a single function `serialize_in_chunks()` which can serialize a Graph into a number of NT files with a maximum number of triples or maximum file size.

There is an option to preserve any prefixes declared for the original graph in the first file, which will be a Turtle file.

rdflib.tools.chunk_serializer.serialize_in_chunks(g, max_triples=10000, max_file_size_kb=None, file_name_stem='chunk', output_dir=None, write_prefixes=False)

  Serializes a given Graph into a series of n-triples with a given length.

  Parameters:

    - g (`Graph`) – The graph to serialize.

    - max_file_size_kb (`Optional`[`int`]) – Maximum size per NT file in kB (1,000 bytes) Equivalent to ~6,000 triples, depending on Literal sizes.

    - max_triples (`int`) –

      Maximum size per NT file in triples Equivalent to lines in file.

      If both this parameter and max_file_size_kb are set, max_file_size_kb will be used.

    - file_name_stem (`str`) – Prefix of each file name. e.g. “chunk” = chunk_000001.nt, chunk_000002.nt…

    - output_dir (`Optional`[`Path`]) – The directory you want the files to be written to.

    - write_prefixes (`bool`) – The first file created is a Turtle file containing original graph prefixes.

  Return type:

    `None`

  See `../test/test_tools/test_chunk_serializer.py` for examples of this in use.

## rdflib.tools.csv2rdf module

A commandline tool for semi-automatically converting CSV to RDF.

See also https://github.com/RDFLib/pyTARQL in the RDFlib family of tools

try: `csv2rdf --help`

class rdflib.tools.csv2rdf.CSV2RDF

  Bases: `object`

  __dict__ = mappingproxy({'__module__': 'rdflib.tools.csv2rdf', '__init__': <function CSV2RDF.__init__>, 'triple': <function CSV2RDF.triple>, 'convert': <function CSV2RDF.convert>, '__dict__': <attribute '__dict__' of 'CSV2RDF' objects>, '__weakref__': <attribute '__weakref__' of 'CSV2RDF' objects>, '__doc__': None, '__annotations__': {'IDENT': 'Union[Tuple[str, ...], str]'}})
  __init__()
  __module__ = 'rdflib.tools.csv2rdf'
  __weakref__

    list of weak references to the object

  convert(csvreader)
  triple(s, p, o)

## rdflib.tools.defined_namespace_creator module

This rdflib Python script creates a DefinedNamespace Python file from a given RDF file

It is a very simple script: it finds all things defined in the RDF file within a given namespace:

> <thing> a ?x

> where ?x is anything and <thing> starts with the given namespace

Nicholas J. Car, Dec, 2021

rdflib.tools.defined_namespace_creator.get_target_namespace_elements(g, target_namespace)
  Parameters:

    - g (`Graph`)

    - target_namespace (`str`)

  Return type:

    `Tuple`[`List`[`Tuple`[`str`, `str`]], `List`[`str`], `List`[`str`]]

rdflib.tools.defined_namespace_creator.make_dn_file(output_file_name, target_namespace, elements_strs, non_python_elements_strs, object_id, fail)
  Parameters:

    - output_file_name (`Path`)

    - target_namespace (`str`)

    - elements_strs (`Iterable`[`str`])

    - non_python_elements_strs (`List`[`str`])

    - object_id (`str`)

    - fail (`bool`)

  Return type:

    `None`

rdflib.tools.defined_namespace_creator.validate_namespace(namespace)
  Parameters:

    namespace (`str`)

  Return type:

    `None`

rdflib.tools.defined_namespace_creator.validate_object_id(object_id)
  Parameters:

    object_id (`str`)

  Return type:

    `None`

## rdflib.tools.graphisomorphism module

A commandline tool for testing if RDF graphs are isomorpic, i.e. equal if BNode labels are ignored.

class rdflib.tools.graphisomorphism.IsomorphicTestableGraph(**kargs)

  Bases: `Graph`

  Ported from: http://www.w3.org/2001/sw/DataAccess/proto-tests/tools/rdfdiff.py (Sean B Palmer’s RDF Graph Isomorphism Tester)

  __abstractmethods__ = frozenset({})
  __annotations__ = {'__identifier': '_ContextIdentifierType', '__store': 'Store', 'base': 'Optional[str]', 'context_aware': 'bool', 'default_union': 'bool', 'formula_aware': 'bool'}
  __eq__(G)

    Graph isomorphism testing.

  __hash__ = None
  __init__(**kargs)
  __module__ = 'rdflib.tools.graphisomorphism'
  __ne__(G)

    Negative graph isomorphism testing.

  hashtriples()
  internal_hash()

    This is defined instead of __hash__ to avoid a circular recursion scenario with the Memory store for rdflib which requires a hash lookup in order to return a generator of triples

  vhash(term, done=False)
  vhashtriple(triple, term, done)
  vhashtriples(term, done)

rdflib.tools.graphisomorphism.main()

## rdflib.tools.rdf2dot module

A commandline tool for drawing RDF graphs in Graphviz DOT format

You can draw the graph of an RDF file directly:

rdflib.tools.rdf2dot.main()

rdflib.tools.rdf2dot.rdf2dot(g, stream, opts={})

  Convert the RDF graph to DOT writes the dot output to the stream

  Parameters:

    - g (`Graph`)

    - stream (`TextIO`)

    - opts (`Dict`[`str`, `Any`])

## rdflib.tools.rdfpipe module

A commandline tool for parsing RDF in different formats and serializing the resulting graph to a chosen format.

rdflib.tools.rdfpipe.main()

rdflib.tools.rdfpipe.make_option_parser()

rdflib.tools.rdfpipe.parse_and_serialize(input_files, input_format, guess, outfile, output_format, ns_bindings, store_conn='', store_type=None)

## rdflib.tools.rdfs2dot module

A commandline tool for drawing RDFS Class diagrams in Graphviz DOT format

You can draw the graph of an RDFS file directly:

rdflib.tools.rdfs2dot.main()

rdflib.tools.rdfs2dot.rdfs2dot(g, stream, opts={})

  Convert the RDFS schema in a graph writes the dot output to the stream

## Module contents

Various commandline tools for working with RDFLib