API reference
pyjelly
Modules:
Name | Description |
---|---|
errors |
|
integrations |
|
jelly |
|
options |
|
parse |
|
serialize |
|
errors
Classes:
Name | Description |
---|---|
JellyConformanceError |
Raised when Jelly conformance is violated. |
JellyAssertionError |
Raised when a recommended assertion from the specification fails. |
JellyNotImplementedError |
Raised when a future feature is not yet implemented. |
JellyConformanceError
Bases: Exception
Raised when Jelly conformance is violated.
JellyAssertionError
Bases: AssertionError
Raised when a recommended assertion from the specification fails.
JellyNotImplementedError
Bases: NotImplementedError
Raised when a future feature is not yet implemented.
integrations
Modules:
Name | Description |
---|---|
rdflib |
|
rdflib
Modules:
Name | Description |
---|---|
parse |
|
serialize |
|
Functions:
Name | Description |
---|---|
register_extension_to_rdflib |
Make rdflib.util.guess_format discover Jelly format. |
register_extension_to_rdflib(extension='.jelly')
Make rdflib.util.guess_format discover Jelly format.
rdflib.util.guess_format("foo.jelly") register_extension_to_rdflib() rdflib.util.guess_format("foo.jelly") 'jelly'
Source code in pyjelly/integrations/rdflib/__init__.py
parse
Classes:
Name | Description |
---|---|
RDFLibAdapter |
RDFLib adapter class, is extended by triples and quads implementations. |
RDFLibTriplesAdapter |
Triples adapter RDFLib implementation. |
RDFLibQuadsAdapter |
Extended RDFLib adapter for the QUADS physical type. |
RDFLibGraphsAdapter |
Extension of RDFLibQuadsBaseAdapter for the GRAPHS physical type. |
RDFLibJellyParser |
|
Functions:
Name | Description |
---|---|
parse_triples_stream |
Parse flat triple stream. |
parse_quads_stream |
Parse flat quads stream. |
parse_jelly_grouped |
Take jelly file and return generators based on the detected logical type. |
parse_jelly_flat |
Parse jelly file with FLAT physical type into one Graph/Dataset. |
RDFLibAdapter(options, parsing_mode=ParsingMode.FLAT)
Bases: Adapter
RDFLib adapter class, is extended by triples and quads implementations.
Args: Adapter (type): abstract adapter class
Source code in pyjelly/parse/decode.py
RDFLibTriplesAdapter(options, graph_factory, parsing_mode=ParsingMode.FLAT)
Bases: RDFLibAdapter
Triples adapter RDFLib implementation.
Notes: has internal graph object which tracks triples and namespaces and can get flushed between frames.
Methods:
Name | Description |
---|---|
frame |
Finalize one frame in triples stream. |
Source code in pyjelly/integrations/rdflib/parse.py
frame()
Finalize one frame in triples stream.
Returns: Graph: frame content as a separate Graph and starts a new Graph
Source code in pyjelly/integrations/rdflib/parse.py
RDFLibQuadsAdapter(options, dataset_factory, parsing_mode=ParsingMode.FLAT)
Bases: RDFLibQuadsBaseAdapter
Extended RDFLib adapter for the QUADS physical type.
Notes: Adds triples and namespaces directly to dataset, so RDFLib handles the rest.
Args: RDFLibQuadsBaseAdapter (type): base quads adapter (shared with graphs physical type)
Source code in pyjelly/integrations/rdflib/parse.py
RDFLibGraphsAdapter(options, dataset_factory, parsing_mode=ParsingMode.FLAT)
Bases: RDFLibQuadsBaseAdapter
Extension of RDFLibQuadsBaseAdapter for the GRAPHS physical type.
Notes: introduces graph start/end, checks if graph exists, dataset store management.
Args: RDFLibQuadsBaseAdapter (type): base adapter for quads management.
Raises: JellyConformanceError: if no graph_start was encountered
Source code in pyjelly/integrations/rdflib/parse.py
RDFLibJellyParser
Bases: Parser
Methods:
Name | Description |
---|---|
parse |
Parse jelly file into provided RDFLib Graph. |
parse(source, sink)
Parse jelly file into provided RDFLib Graph.
Args: source (InputSource): jelly file as buffered binary stream InputSource obj sink (Graph): RDFLib Graph
Raises: TypeError: raises error if invalid input
Source code in pyjelly/integrations/rdflib/parse.py
parse_triples_stream(frames, options, graph_factory, parsing_mode=ParsingMode.FLAT)
Parse flat triple stream.
Args: frames (Iterable[jelly.RdfStreamFrame]): iterator over stream frames options (ParserOptions): stream options graph_factory (Callable): Lambda to construct a graph parsing_mode (ParsingMode): specifies whether this is a flat or grouped parsing.
Yields: Generator[Graph]: RDFLib Graph(s)
Source code in pyjelly/integrations/rdflib/parse.py
parse_quads_stream(frames, options, dataset_factory, parsing_mode=ParsingMode.FLAT)
Parse flat quads stream.
Args: frames (Iterable[jelly.RdfStreamFrame]): iterator over stream frames options (ParserOptions): stream options dataset_factory (Callable): Lambda to construct a dataset parsing_mode (ParsingMode): specifies whether this is a flat or grouped parsing.
Yields: Generator[Dataset]: RDFLib dataset(s)
Source code in pyjelly/integrations/rdflib/parse.py
parse_jelly_grouped(inp, graph_factory, dataset_factory)
Take jelly file and return generators based on the detected logical type.
Yields one graph/dataset per frame.
Args: inp (IO[bytes]): input jelly buffered binary stream graph_factory (Callable): lambda to construct a Graph dataset_factory (Callable): lambda to construct a Dataset
Raises: NotImplementedError: is raised if a logical type is not implemented
Yields: Generator[Any] | Generator[Dataset] | Generator[Graph]: returns generators for graphs/datasets based on the type of input
Source code in pyjelly/integrations/rdflib/parse.py
parse_jelly_flat(inp, graph_factory, dataset_factory)
Parse jelly file with FLAT physical type into one Graph/Dataset.
Args: inp (IO[bytes]): input jelly buffered binary stream graph_factory (Callable): lambda to construct a Graph dataset_factory (Callable): lambda to construct a Dataset
Raises: NotImplementedError: if physical type is not supported
Returns: RDFLib Graph or Dataset
Source code in pyjelly/integrations/rdflib/parse.py
serialize
Classes:
Name | Description |
---|---|
RDFLibTermEncoder |
|
RDFLibJellySerializer |
RDFLib serializer for writing graphs in Jelly RDF stream format. |
Functions:
Name | Description |
---|---|
triples_stream_frames |
Serialize a Graph/Dataset into jelly frames. |
quads_stream_frames |
Serialize a Dataset into jelly frames. |
graphs_stream_frames |
Serialize a Dataset into jelly frames as a stream of graphs. |
RDFLibTermEncoder(lookup_preset=None)
Bases: TermEncoder
Methods:
Name | Description |
---|---|
encode_any |
Encode term based on its RDFLib object. |
Source code in pyjelly/serialize/encode.py
encode_any(term, slot)
Encode term based on its RDFLib object.
Args: term (object): term to encode slot (Slot): its place in statement.
Returns: RowsAndTerm: encoded extra rows and a jelly term to encode
Source code in pyjelly/integrations/rdflib/serialize.py
RDFLibJellySerializer(store)
Bases: Serializer
RDFLib serializer for writing graphs in Jelly RDF stream format.
Handles streaming RDF terms into Jelly frames using internal encoders. Supports only graphs and datasets (not quoted graphs).
Methods:
Name | Description |
---|---|
guess_options |
Guess the serializer options based on the store type. |
guess_stream |
Return an appropriate stream implementation for the given options. |
serialize |
Serialize self.store content to Jelly format. |
Source code in pyjelly/integrations/rdflib/serialize.py
guess_options()
Guess the serializer options based on the store type.
RDFLibJellySerializer(Graph()).guess_options().logical_type 1 RDFLibJellySerializer(Dataset()).guess_options().logical_type 2
Source code in pyjelly/integrations/rdflib/serialize.py
guess_stream(options)
Return an appropriate stream implementation for the given options.
graph_ser = RDFLibJellySerializer(Graph()) ds_ser = RDFLibJellySerializer(Dataset())
type(graph_ser.guess_stream(graph_ser.guess_options()))
type(ds_ser.guess_stream(ds_ser.guess_options()))
Source code in pyjelly/integrations/rdflib/serialize.py
serialize(out, /, *, stream=None, options=None, **unused)
Serialize self.store content to Jelly format.
Args: out (IO[bytes]): output buffered writer stream (Stream | None, optional): Jelly stream object. Defaults to None. options (SerializerOptions | None, optional): Serializer options if defined beforehand, e.g., read from a separate file. Defaults to None. **unused(Any): unused args for RDFLib serialize
Source code in pyjelly/integrations/rdflib/serialize.py
triples_stream_frames(stream, data)
Serialize a Graph/Dataset into jelly frames.
Args: stream (TripleStream): stream that specifies triples processing data (Graph | Dataset): Graph/Dataset to serialize.
Notes: if Dataset is given, its graphs are unpacked and iterated over if flow is GraphsFrameFlow, emits a frame per graph.
Yields: Generator[jelly.RdfStreamFrame]: jelly frames.
Source code in pyjelly/integrations/rdflib/serialize.py
quads_stream_frames(stream, data)
Serialize a Dataset into jelly frames.
Notes: Emits one frame per dataset if flow is of DatasetsFrameFlow.
Args: stream (QuadStream): stream that specifies quads processing data (Dataset): Dataset to serialize.
Yields: Generator[jelly.RdfStreamFrame]: jelly frames
Source code in pyjelly/integrations/rdflib/serialize.py
graphs_stream_frames(stream, data)
Serialize a Dataset into jelly frames as a stream of graphs.
Notes: If flow of DatasetsFrameFlow type, the whole dataset will be encoded into one frame.
Args: stream (GraphStream): stream that specifies graphs processing data (Dataset): Dataset to serialize.
Yields: Generator[jelly.RdfStreamFrame]: jelly frames
Source code in pyjelly/integrations/rdflib/serialize.py
jelly
Modules:
Name | Description |
---|---|
rdf_pb2 |
Generated protocol buffer code. |
rdf_pb2
Generated protocol buffer code.
options
Functions:
Name | Description |
---|---|
register_mimetypes |
Associate files that have Jelly extension with Jelly MIME types. |
Attributes:
Name | Type | Description |
---|---|---|
INTEGRATION_SIDE_EFFECTS |
bool
|
Whether to allow integration module imports to trigger side effects. |
INTEGRATION_SIDE_EFFECTS = True
Whether to allow integration module imports to trigger side effects.
These side effects are cheap and may include populating some registries for guessing the defaults for external integrations that work with Jelly.
register_mimetypes(extension='.jelly')
Associate files that have Jelly extension with Jelly MIME types.
register_mimetypes() mimetypes.guess_type("out.jelly") ('application/x-jelly-rdf', None)
Source code in pyjelly/options.py
parse
Modules:
Name | Description |
---|---|
decode |
|
ioutils |
|
lookup |
|
decode
Classes:
Name | Description |
---|---|
ParsingMode |
Specifies how jelly frames should be treated. |
Decoder |
|
Functions:
Name | Description |
---|---|
options_from_frame |
Fill stream options based on the options row. |
ParsingMode
Bases: Enum
Specifies how jelly frames should be treated.
Modes: FLAT Yield all frames as one Graph or Dataset. GROUPED Yield one Graph/Dataset per frame (grouped parsing).
Decoder(adapter)
Initializes decoder with a lookup tables with preset sizes, integration-dependent adapter and empty repeated terms dictionary.
Args: adapter (Adapter): integration-dependent adapter that specifies terms conversion to specific objects, framing, namespace declarations, and graphs/datasets forming.
Methods:
Name | Description |
---|---|
decode_frame |
Decode a frame to custom object based on adapter implementation. |
decode_row |
Decode a row based on its type. |
ingest_prefix_entry |
Update prefix lookup table based on the table entry. |
ingest_name_entry |
Update name lookup table based on the table entry. |
ingest_datatype_entry |
Update datatype lookup table based on the table entry. |
decode_term |
Decode a term based on its type: IRI/literal/BN/default graph. |
decode_iri |
Decode RdfIri message to IRI using a custom adapter. |
decode_bnode |
Decode string message to blank node (BN) using a custom adapter. |
decode_literal |
Decode RdfLiteral to literal based on custom adapter implementation. |
decode_statement |
Decode a triple/quad message. |
Source code in pyjelly/parse/decode.py
decode_frame(frame)
Decode a frame to custom object based on adapter implementation.
Args: frame (jelly.RdfStreamFrame): jelly frame
Returns: Any: custom obj based on adapter logic
Source code in pyjelly/parse/decode.py
decode_row(row)
Decode a row based on its type.
Notes: uses custom adapters to decode triples/quads, namespace declarations, graph start/end.
Args: row (Any): protobuf row message
Raises: TypeError: raises error if this type of protobuf message does not have a respective handler
Returns: Any | None: decoded row - result from calling decode_row (row type appropriate handler)
Source code in pyjelly/parse/decode.py
ingest_prefix_entry(entry)
Update prefix lookup table based on the table entry.
Args: entry (jelly.RdfPrefixEntry): prefix message, containing id and value
Source code in pyjelly/parse/decode.py
ingest_name_entry(entry)
Update name lookup table based on the table entry.
Args: entry (jelly.RdfNameEntry): name message, containing id and value
Source code in pyjelly/parse/decode.py
ingest_datatype_entry(entry)
Update datatype lookup table based on the table entry.
Args: entry (jelly.RdfDatatypeEntry): name message, containing id and value
Source code in pyjelly/parse/decode.py
decode_term(term)
Decode a term based on its type: IRI/literal/BN/default graph.
Notes: requires a custom adapter with implemented methods for terms decoding.
Args: term (Any): IRI/literal/BN(string)/Default graph message
Raises: TypeError: raises error if no handler for the term is found
Returns: Any: decoded term (currently, rdflib objects, e.g., rdflib.term.URIRef)
Source code in pyjelly/parse/decode.py
decode_iri(iri)
Decode RdfIri message to IRI using a custom adapter.
Args: iri (jelly.RdfIri): RdfIri message
Returns: Any: IRI, based on adapter implementation, e.g., rdflib.term.URIRef
Source code in pyjelly/parse/decode.py
decode_bnode(bnode)
Decode string message to blank node (BN) using a custom adapter.
Args: bnode (str): blank node id
Returns: Any: blank node object from the custom adapter
Source code in pyjelly/parse/decode.py
decode_literal(literal)
Decode RdfLiteral to literal based on custom adapter implementation.
Notes: checks for langtag existence; for datatype checks for non-zero table size and datatype field presence
Args: literal (jelly.RdfLiteral): RdfLiteral message
Returns: Any: literal returned by the custom adapter
Source code in pyjelly/parse/decode.py
decode_statement(statement, oneofs)
Decode a triple/quad message.
Notes: also updates repeated terms dictionary
Args: statement (jelly.RdfTriple | jelly.RdfQuad): triple/quad message oneofs (Sequence[str]): terms s/p/o/g(if quads)
Raises: ValueError: if a missing repeated term is encountered
Returns: Any: a list of decoded terms
Source code in pyjelly/parse/decode.py
options_from_frame(frame, *, delimited)
Fill stream options based on the options row.
Notes: generalized_statements, rdf_star, and namespace declarations are set to false by default
Args: frame (jelly.RdfStreamFrame): first non-empty frame from the stream delimited (bool): derived delimited flag
Returns: ParserOptions: filled options with types/lookups/stream parameters information
Source code in pyjelly/parse/decode.py
ioutils
Functions:
Name | Description |
---|---|
delimited_jelly_hint |
Detect whether a Jelly file is delimited from its first 3 bytes. |
get_options_and_frames |
Return stream options and frames from the buffered binary stream. |
delimited_jelly_hint(header)
Detect whether a Jelly file is delimited from its first 3 bytes.
Truth table (notation: 0A
= 0x0A
, NN
= not 0x0A
, ??
= don't care):
Byte 1 | Byte 2 | Byte 3 | Result |
---|---|---|---|
NN |
?? |
?? |
Delimited |
0A |
NN |
?? |
Non-delimited |
0A |
0A |
NN |
Delimited (size = 10) |
0A |
0A |
0A |
Non-delimited (stream options size = 10) |
delimited_jelly_hint(bytes([0x00, 0x00, 0x00])) True
delimited_jelly_hint(bytes([0x00, 0x00, 0x0A])) True
delimited_jelly_hint(bytes([0x00, 0x0A, 0x00])) True
delimited_jelly_hint(bytes([0x00, 0x0A, 0x0A])) True
delimited_jelly_hint(bytes([0x0A, 0x00, 0x00])) False
delimited_jelly_hint(bytes([0x0A, 0x00, 0x0A])) False
delimited_jelly_hint(bytes([0x0A, 0x0A, 0x00])) True
delimited_jelly_hint(bytes([0x0A, 0x0A, 0x0A])) False
Source code in pyjelly/parse/ioutils.py
get_options_and_frames(inp)
Return stream options and frames from the buffered binary stream.
Args: inp (IO[bytes]): jelly buffered binary stream
Raises: JellyConformanceError: if no non-empty frames detected in the delimited stream JellyConformanceError: if non-delimited, error is raised if no rows are detected (empty frame)
Returns: tuple[ParserOptions, Iterator[jelly.RdfStreamFrame]]: ParserOptions holds: stream types, lookup presets and other stream options
Source code in pyjelly/parse/ioutils.py
lookup
Classes:
Name | Description |
---|---|
LookupDecoder |
Shared base for RDF lookup encoders using Jelly compression. |
LookupDecoder(*, lookup_size)
Shared base for RDF lookup encoders using Jelly compression.
Tracks the last assigned and last reused index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lookup_size
|
int
|
Maximum lookup size. |
required |
Source code in pyjelly/parse/lookup.py
serialize
Modules:
Name | Description |
---|---|
encode |
|
flows |
|
lookup |
|
streams |
|
encode
Classes:
Name | Description |
---|---|
TermEncoder |
|
Slot |
Slots for encoding RDF terms. |
Functions:
Name | Description |
---|---|
split_iri |
Split iri into prefix and name. |
encode_statement |
Encode a statement. |
encode_triple |
Encode one triple. |
encode_quad |
Encode one quad. |
encode_namespace_declaration |
Encode namespace declaration. |
encode_options |
Encode stream options to ProtoBuf message. |
TermEncoder(lookup_preset=None)
Methods:
Name | Description |
---|---|
encode_iri |
Encode iri. |
encode_default_graph |
Encode default graph. |
encode_bnode |
Encode blank node (BN). |
encode_literal |
Encode literal. |
Source code in pyjelly/serialize/encode.py
encode_iri(iri_string)
Encode iri.
Args: iri_string (str): full iri in string format.
Returns: RowsAnd[jelly.RdfIri]: extra rows and protobuf RdfIri message.
Source code in pyjelly/serialize/encode.py
encode_default_graph()
Encode default graph.
Returns: RowsAnd[jelly.RdfDefaultGraph]: empty extra rows and default graph message.
encode_bnode(bnode)
Encode blank node (BN).
Args: bnode (str): BN internal identifier in string format.
Returns: RowsAnd[str]: empty extra rows and original BN string.
Source code in pyjelly/serialize/encode.py
encode_literal(*, lex, language=None, datatype=None)
Encode literal.
Args: lex (str): lexical form/literal value language (str | None, optional): langtag. Defaults to None. datatype (str | None, optional): data type if it is a typed literal. Defaults to None.
Raises: JellyConformanceError: if datatype specified while datatable is not used.
Returns: RowsAnd[jelly.RdfLiteral]: extra rows (i.e., datatype entries) and RdfLiteral message.
Source code in pyjelly/serialize/encode.py
split_iri(iri_string)
Split iri into prefix and name.
Args: iri_string (str): full iri string.
Returns: tuple[str, str]: iri's prefix and name.
Source code in pyjelly/serialize/encode.py
encode_statement(terms, term_encoder, repeated_terms)
Encode a statement.
Args: terms (Iterable[object]): original terms to encode term_encoder (TermEncoder): encoder with lookup tables repeated_terms (dict[Slot, object]): dictionary of repeated terms.
Returns: tuple[list[jelly.RdfStreamRow], dict[str, Any]]: extra rows to append and jelly terms.
Source code in pyjelly/serialize/encode.py
encode_triple(terms, term_encoder, repeated_terms)
Encode one triple.
Args: terms (Iterable[object]): original terms to encode term_encoder (TermEncoder): current encoder with lookup tables repeated_terms (dict[Slot, object]): dictionary of repeated terms.
Returns: list[jelly.RdfStreamRow]: list of rows to add to the current flow.
Source code in pyjelly/serialize/encode.py
encode_quad(terms, term_encoder, repeated_terms)
Encode one quad.
Args: terms (Iterable[object]): original terms to encode term_encoder (TermEncoder): current encoder with lookup tables repeated_terms (dict[Slot, object]): dictionary of repeated terms.
Returns: list[jelly.RdfStreamRow]: list of messages to append to current flow.
Source code in pyjelly/serialize/encode.py
encode_namespace_declaration(name, value, term_encoder)
Encode namespace declaration.
Args: name (str): namespace prefix label value (str): namespace iri term_encoder (TermEncoder): current encoder
Returns: list[jelly.RdfStreamRow]: list of messages to append to current flow.
Source code in pyjelly/serialize/encode.py
encode_options(lookup_preset, stream_types, params)
Encode stream options to ProtoBuf message.
Args: lookup_preset (options.LookupPreset): lookup tables options stream_types (options.StreamTypes): physical and logical types params (options.StreamParameters): other params.
Returns: jelly.RdfStreamRow: encoded stream options row
Source code in pyjelly/serialize/encode.py
flows
Classes:
Name | Description |
---|---|
FrameFlow |
Abstract base class for producing Jelly frames from RDF stream rows. |
ManualFrameFlow |
Produces frames only when manually requested (never automatically). |
BoundedFrameFlow |
Produce frames automatically when a fixed number of rows is reached. |
GraphsFrameFlow |
|
DatasetsFrameFlow |
|
Functions:
Name | Description |
---|---|
flow_for_type |
Return flow based on logical type requested. |
FrameFlow
Bases: UserList[RdfStreamRow]
Abstract base class for producing Jelly frames from RDF stream rows.
Collects stream rows and assembles them into RdfStreamFrame objects when ready.
Methods:
Name | Description |
---|---|
frame_from_graph |
Treat the current rows as a graph and produce a frame. |
frame_from_dataset |
Treat the current rows as a dataset and produce a frame. |
to_stream_frame |
Create stream frame from flow content. |
frame_from_graph()
Treat the current rows as a graph and produce a frame.
Default implementation returns None.
frame_from_dataset()
Treat the current rows as a dataset and produce a frame.
Default implementation returns None.
to_stream_frame()
Create stream frame from flow content.
Notes: Clears flow content after creating the frame.
Returns: jelly.RdfStreamFrame | None: stream frame
Source code in pyjelly/serialize/flows.py
ManualFrameFlow(initlist=None, *, logical_type=jelly.LOGICAL_STREAM_TYPE_UNSPECIFIED)
Bases: FrameFlow
Produces frames only when manually requested (never automatically).
Warning
All stream rows are kept in memory until to_stream_frame()
is called.
This may lead to high memory usage for large streams.
Used for non-delimited serialization.
Source code in pyjelly/serialize/flows.py
BoundedFrameFlow(initlist=None, *, frame_size=None)
Bases: FrameFlow
Produce frames automatically when a fixed number of rows is reached.
Used for delimited encoding (default mode).
Methods:
Name | Description |
---|---|
frame_from_bounds |
Emit frame from flow if full. |
Source code in pyjelly/serialize/flows.py
frame_from_bounds()
Emit frame from flow if full.
Returns: jelly.RdfStreamFrame | None: stream frame
Source code in pyjelly/serialize/flows.py
GraphsFrameFlow
Bases: FrameFlow
Methods:
Name | Description |
---|---|
frame_from_graph |
Emit current flow content (one graph) as jelly frame. |
frame_from_graph()
Emit current flow content (one graph) as jelly frame.
Returns: jelly.RdfStreamFrame | None: jelly frame or none if flow is empty.
Source code in pyjelly/serialize/flows.py
DatasetsFrameFlow
Bases: FrameFlow
Methods:
Name | Description |
---|---|
frame_from_dataset |
Emit current flow content (dataset) as jelly frame. |
frame_from_dataset()
Emit current flow content (dataset) as jelly frame.
Returns: jelly.RdfStreamFrame | None: jelly frame or none if flow is empty.
Source code in pyjelly/serialize/flows.py
flow_for_type(logical_type)
Return flow based on logical type requested.
Args: logical_type (jelly.LogicalStreamType): logical type requested.
Raises: NotImplementedError: if logical type not supported.
Returns: type[FrameFlow]: FrameFlow for respective logical type.
Source code in pyjelly/serialize/flows.py
lookup
Classes:
Name | Description |
---|---|
Lookup |
Fixed-size 1-based string-to-index mapping with LRU eviction. |
LookupEncoder |
Shared base for RDF lookup encoders using Jelly compression. |
Lookup(max_size)
Fixed-size 1-based string-to-index mapping with LRU eviction.
- Assigns incrementing indices starting from 1.
- After reaching the maximum size, reuses the existing indices from evicting the least-recently-used entries.
- Index 0 is reserved for delta encoding in Jelly streams.
To check if a key exists, use .move(key)
and catch KeyError
.
If KeyError
is raised, the key can be inserted with .insert(key)
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_size
|
int
|
Maximum number of entries. Zero disables lookup. |
required |
Source code in pyjelly/serialize/lookup.py
LookupEncoder(*, lookup_size)
Shared base for RDF lookup encoders using Jelly compression.
Tracks the last assigned and last reused index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lookup_size
|
int
|
Maximum lookup size. |
required |
Methods:
Name | Description |
---|---|
encode_entry_index |
Get or assign the index to use in an entry. |
Source code in pyjelly/serialize/lookup.py
encode_entry_index(key)
Get or assign the index to use in an entry.
Returns:
Type | Description |
---|---|
int or None
|
|
If the return value is None, the entry is already in the lookup and does not
|
|
need to be emitted. Any integer value (including 0) means the entry is new
|
|
and should be emitted.
|
|
Source code in pyjelly/serialize/lookup.py
streams
Classes:
Name | Description |
---|---|
Stream |
|
TripleStream |
|
QuadStream |
|
GraphStream |
|
Functions:
Name | Description |
---|---|
stream_for_type |
Give a Stream based on physical type specified. |
Stream(*, encoder, options=None)
Methods:
Name | Description |
---|---|
infer_flow |
Return flow based on the stream options provided. |
enroll |
Initialize start of the stream. |
stream_options |
Encode and append stream options row to the current flow. |
namespace_declaration |
Add namespace declaration to jelly stream. |
for_rdflib |
Initialize stream with RDFLib encoder. |
Source code in pyjelly/serialize/streams.py
infer_flow()
Return flow based on the stream options provided.
Returns: FrameFlow: initialised FrameFlow object.
Source code in pyjelly/serialize/streams.py
enroll()
stream_options()
Encode and append stream options row to the current flow.
Source code in pyjelly/serialize/streams.py
namespace_declaration(name, iri)
Add namespace declaration to jelly stream.
Args: name (str): namespace prefix label iri (str): namespace iri
Source code in pyjelly/serialize/streams.py
for_rdflib(options=None)
Initialize stream with RDFLib encoder.
Args: options (SerializerOptions | None, optional): Stream options. Defaults to None.
Raises: TypeError: if Stream is passed, and not a Stream for specific physical type.
Returns: Stream: initialized stream with RDFLib encoder.
Source code in pyjelly/serialize/streams.py
TripleStream(*, encoder, options=None)
Bases: Stream
Methods:
Name | Description |
---|---|
triple |
Process one triple to Protobuf messages. |
Source code in pyjelly/serialize/streams.py
triple(terms)
Process one triple to Protobuf messages.
Note: Adds new rows to the current flow and returns StreamFrame if frame size conditions are met.
Args: terms (Iterable[object]): RDF terms to encode.
Returns: jelly.RdfStreamFrame | None: stream frame if flow supports frames slicing and current flow is full
Source code in pyjelly/serialize/streams.py
QuadStream(*, encoder, options=None)
Bases: Stream
Methods:
Name | Description |
---|---|
quad |
Process one quad to Protobuf messages. |
Source code in pyjelly/serialize/streams.py
quad(terms)
Process one quad to Protobuf messages.
Args: terms (Iterable[object]): terms to encode.
Returns: jelly.RdfStreamFrame | None: stream frame if flow supports frames slicing and current flow is full
Source code in pyjelly/serialize/streams.py
GraphStream(*, encoder, options=None)
Bases: TripleStream
Methods:
Name | Description |
---|---|
graph |
Process one graph into a sequence of jelly frames. |
Source code in pyjelly/serialize/streams.py
graph(graph_id, graph)
Process one graph into a sequence of jelly frames.
Args: graph_id (object): graph id (BN, Literal, iri, default) graph (Iterable[Iterable[object]]): iterable of triples (graph's content)
Yields: Generator[jelly.RdfStreamFrame]: jelly frames.
Source code in pyjelly/serialize/streams.py
stream_for_type(physical_type)
Give a Stream based on physical type specified.
Args: physical_type (jelly.PhysicalStreamType): jelly stream physical type.
Raises: NotImplementedError: if no stream for requested physical type is available.
Returns: type[Stream]: jelly stream