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 |
|---|---|
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
serialize
Classes:
| Name | Description |
|---|---|
RDFLibJellySerializer |
RDFLib serializer for writing graphs in Jelly RDF stream format. |
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).
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 |
|---|---|
ioutils |
|
lookup |
|
ioutils
Functions:
| Name | Description |
|---|---|
delimited_jelly_hint |
Detect whether a Jelly file is delimited from its first 3 bytes. |
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
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 |
|
encode
Classes:
| Name | Description |
|---|---|
Slot |
Slots for encoding RDF terms. |
Functions:
| Name | Description |
|---|---|
new_repeated_terms |
Create a new dictionary for repeated terms. |
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 |
Produces frames automatically when a fixed number of rows is reached. |
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 |
|---|---|
__init_subclass__ |
Register subclasses of FrameFlow with their logical stream type. |
__init_subclass__()
Register subclasses of FrameFlow with their logical stream type.
This allows for dynamic dispatch based on the logical stream type.
Source code in pyjelly/serialize/flows.py
ManualFrameFlow
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.
BoundedFrameFlow(initlist=None, *, frame_size=None)
Bases: FrameFlow
Produces frames automatically when a fixed number of rows is reached.
Used for delimited encoding (default mode).
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.
|
|