Turtle Format (RDF)
Description
Turtle is a text-based format for representing RDF (Resource Description Framework) data. It's a human-readable serialization of RDF graphs. Turtle files represent RDF triples (subject-predicate-object) in a compact, readable format.
File Extensions
.ttl- Turtle RDF files.turtle- Turtle RDF files (alias)
Implementation Details
Reading
The Turtle implementation:
- Uses
rdfliblibrary for parsing - Parses RDF triples from Turtle format
- Groups triples by subject
- Converts each subject to a dictionary with its properties
- Supports optional subject/predicate filtering
Writing
Writing support:
- Serializes each record as RDF triples via
rdflib - Uses
subjector@idas the subject URI; other keys become predicates - Install with
pip install iterabledata[rdf]
Key Features
- RDF format: Represents RDF data
- Human-readable: More readable than RDF/XML
- Triple grouping: Groups triples by subject
- Nested data: Supports complex RDF structures
- Filtering: Can filter by subject or predicate
Usage
from iterable import open_iterable
# Basic reading
with open_iterable('data.ttl') as source:
for row in source:
print(row) # Each row represents a subject with its properties
# Filter by subject
source = open_iterable('data.ttl', iterableargs={
'subject': 'http://example.org/person1'
})
# Writing
with open_iterable('output.ttl', mode='w') as dest:
dest.write({
'subject': 'http://example.org/alice',
'http://xmlns.com/foaf/0.1/name': 'Alice',
})
Parameters
subject(str): Optional - Filter by subject URIpredicate(str): Optional - Filter by predicate URIencoding(str): File encoding (default:utf8)
Limitations
- RDF extra: Requires
pip install iterabledata[rdf](rdflib) - Memory usage: Entire RDF graph is loaded into memory
- RDF complexity: Complex RDF structures may be difficult to work with
- Triple grouping: Triples are grouped by subject, which may not match all use cases
Compression Support
Turtle files can be compressed with all supported codecs:
- GZip (
.ttl.gz) - BZip2 (
.ttl.bz2) - LZMA (
.ttl.xz) - LZ4 (
.ttl.lz4) - ZIP (
.ttl.zip) - Brotli (
.ttl.br) - ZStandard (
.ttl.zst)
Use Cases
- Semantic web: Working with semantic web data
- Linked data: Processing linked data
- Knowledge graphs: Building and querying knowledge graphs
- Metadata: Working with RDF metadata
Error Handling
- Missing dependency: optional libraries raise
ImportErrorwith an install hint (pip install 'iterabledata[<extra>]'when an extra exists). - Write mode: read-only formats raise
WriteNotSupportedErrororValueErrorwhen opened withmode="w". - Bad or unsupported input: may raise
ValueError,OSError, or library-specific errors. - See Troubleshooting for decoding, detection, and engine issues.