Skip to content

# `` nt

Classes:

- `NTSerializer` –

  Serializes RDF graphs to NTriples format.

## `` __all__ `module-attribute`

    __all__ = ['NTSerializer']

## `` NT11Serializer

    NT11Serializer(store: Graph)

Bases: `NTSerializer`

Serializes RDF graphs to RDF 1.1 NTriples format.

Exactly like nt - only utf8 encoded.

Source code in `rdflib/plugins/serializers/nt.py`

    54
    55

    def __init__(self, store: Graph):
        Serializer.__init__(self, store)  # default to utf-8

## `` NTSerializer

    NTSerializer(store: Graph)

Bases: `Serializer`

Serializes RDF graphs to NTriples format.

Methods:

- `serialize` –

Source code in `rdflib/plugins/serializers/nt.py`

    26
    27

    def __init__(self, store: Graph):
        Serializer.__init__(self, store)

### `` serialize

    serialize(stream: IO[bytes], base: Optional[str] = None, encoding: Optional[str] = 'utf-8', **kwargs: Any) -> None

Source code in `rdflib/plugins/serializers/nt.py`

    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45

    def serialize(
        self,
        stream: IO[bytes],
        base: Optional[str] = None,
        encoding: Optional[str] = "utf-8",
        **kwargs: Any,
    ) -> None:
        if base is not None:
            warnings.warn("NTSerializer does not support base.")
        if encoding != "utf-8":
            warnings.warn(
                "NTSerializer always uses UTF-8 encoding. "
                f"Given encoding was: {encoding}"
            )

        for triple in self.store:
            stream.write(_nt_row(triple).encode())