Skip to content

# `` serializer

Serializer plugin interface.

This module is useful for those wanting to write a serializer that can plugin to rdflib. If you are wanting to invoke a serializer you likely want to do so through the Graph class serialize method.

TODO: info for how to write a serializer that can plugin to rdflib. See also `rdflib.plugin`

Classes:

- `Serializer` –

## `` __all__ `module-attribute`

    __all__ = ['Serializer']

## `` Serializer

    Serializer(store: Graph)

Methods:

- `relativize` –
- `serialize` –

  Abstract method

Attributes:

- `base` (`Optional[str]`) –
- `encoding` (`str`) –
- `store` (`Graph`) –

Source code in `rdflib/serializer.py`

    27
    28
    29
    30

    def __init__(self, store: Graph):
        self.store: Graph = store
        self.encoding: str = "utf-8"
        self.base: Optional[str] = None

### `` base `instance-attribute`

    base: Optional[str] = None

### `` encoding `instance-attribute`

    encoding: str = 'utf-8'

### `` store `instance-attribute`

    store: Graph = store

### `` relativize

    relativize(uri: _StrT) -> Union[_StrT, URIRef]

Source code in `rdflib/serializer.py`

    41
    42
    43
    44
    45
    46

    def relativize(self, uri: _StrT) -> Union[_StrT, URIRef]:
        base = self.base
        if base is not None and uri.startswith(base):
            # type error: Incompatible types in assignment (expression has type "str", variable has type "Node")
            uri = URIRef(uri.replace(base, "", 1))  # type: ignore[assignment]
        return uri

### `` serialize

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

Abstract method

Source code in `rdflib/serializer.py`

    32
    33
    34
    35
    36
    37
    38
    39

    def serialize(
        self,
        stream: IO[bytes],
        base: Optional[str] = None,
        encoding: Optional[str] = None,
        **args: Any,
    ) -> None:
        """Abstract method"""