# How to Export Knowledge Graphs to RDF, Parquet, or Cypher Formats in Semantica

> Easily export knowledge graphs to RDF, Parquet, or Cypher formats using Semantica's modular export framework. Learn how to convert your graph data efficiently.

- Repository: [Semantica /semantica](https://github.com/semantica-agi/semantica)
- Tags: how-to-guide
- Published: 2026-08-14

---

**Semantica provides a modular export framework with three specialized exporter classes—`RDFExporter`, `ParquetExporter`, and `LPGExporter`—that convert knowledge graphs to RDF (Turtle, RDF/XML, JSON-LD), Parquet, or Cypher formats through a unified API.**

The `semantica-agi/semantica` repository implements a pluggable architecture for **exporting knowledge graphs** to industry-standard formats. Whether you need semantic web compatibility, columnar analytics, or graph database imports, Semantica's export system handles validation, serialization, and file I/O through dedicated exporter classes.

## The Three Core Exporters

Semantica's export framework centers on three format-specific implementations located in `semantica/export/`:

| Exporter | Target Format | Key Responsibilities |
|----------|-------------|----------------------|
| `RDFExporter` | RDF (Turtle, RDF/XML, JSON-LD, N-Triples, N3) | Namespace management, syntax validation, string/file output |
| `ParquetExporter` | Apache Parquet | Arrow schemas, multi-file exports, compression codecs |
| `LPGExporter` | Cypher (Neo4j, Memgraph) | `CREATE` statements, indexes/constraints, `.cypher` scripts |

Each exporter inherits common progress tracking via `get_progress_tracker()` and follows a consistent validation-then-serialization pattern.

## Exporting to RDF Formats

The `RDFExporter` class in [`semantica/export/rdf_exporter.py`](https://github.com/semantica-agi/semantica/blob/main/semantica/export/rdf_exporter.py) (lines 910–965) handles all RDF serializations through a unified interface.

### Supported RDF Syntaxes

- **Turtle** (`turtle`) — human-readable, compact
- **RDF/XML** (`xml`) — traditional XML syntax
- **JSON-LD** (`json-ld`) — JavaScript-native linked data
- **N-Triples** (`ntriples`) — line-based, streaming-friendly
- **N3** (`n3`) — Notation3 with rules support

### RDF Export Example

```python
from semantica.export import RDFExporter

kg = {
    "entities": [
        {"id": "E1", "type": "Person", "name": "Alice"},
        {"id": "E2", "type": "City", "name": "Wonderland"},
    ],
    "relationships": [
        {"source_id": "E1", "target_id": "E2", "type": "LIVES_IN"}
    ],
}

rdf_exporter = RDFExporter()
turtle_str = rdf_exporter.export_to_rdf(kg, format="turtle")
print(turtle_str)

```

The `RDFExporter` uses an internal `NamespaceManager` for prefix handling and `RDFValidator` for syntax compliance before `RDFSerializer` produces the final output. Return type depends on the call: string for in-memory use, file write for persistence.

## Exporting to Parquet Format

The `ParquetExporter` in [`semantica/export/parquet_exporter.py`](https://github.com/semantica-agi/semantica/blob/main/semantica/export/parquet_exporter.py) (lines 93–115) converts knowledge graphs to columnar Parquet files optimized for analytics workloads.

### Parquet Export Features

- **Explicit Arrow schemas** for type-safe `entities` and `relationships` tables
- **Multi-file output**: separate `entities.parquet` and `relationships.parquet` files
- **Compression codecs**: `snappy`, `gzip`, `brotli`, `zstd`, `lz4`

```python
from semantica.export import ParquetExporter

parquet_exporter = ParquetExporter(compression="gzip")
parquet_exporter.export_knowledge_graph(kg, "kg_parquet")

# Creates: kg_parquet/entities.parquet, kg_parquet/relationships.parquet

```

The Arrow schema definition ensures consistent types across exports—critical for downstream tools like Pandas, Polars, or DuckDB.

## Exporting to Cypher (LPG) Format

The `LPGExporter` in [`semantica/export/lpg_exporter.py`](https://github.com/semantica-agi/semantica/blob/main/semantica/export/lpg_exporter.py) (lines 32–50) generates Cypher scripts for **Labeled Property Graph** databases including Neo4j and Memgraph.

### Cypher Export Capabilities

- `CREATE` statements for nodes and relationships with properties
- Optional index and constraint definitions for performance
- Batch processing via configurable `batch_size`

```python
from semantica.export import LPGExporter

lpg_exporter = LPGExporter(batch_size=500)
lpg_exporter.export_knowledge_graph(kg, "kg.cypher")

# Produces: kg.cypher with executable Cypher statements

```

The output file can be executed directly via Neo4j Browser, `cypher-shell`, or Memgraph's import tools. Property sanitization ensures Cypher-legal identifiers.

## High-Level API: Automatic Format Detection

For most use cases, the `export_knowledge_graph` function in [`semantica/export/methods.py`](https://github.com/semantica-agi/semantica/blob/main/semantica/export/methods.py) (lines 865–902) provides the cleanest interface. It dispatches to the appropriate exporter based on the `format` parameter or file extension.

```python
from semantica.export.methods import export_knowledge_graph

# RDF Turtle by explicit format

export_knowledge_graph(kg, "my_graph.ttl", format="turtle")

# Parquet (inferred from directory path)

export_knowledge_graph(kg, "my_graph_parquet", format="parquet")

# Cypher with explicit format

export_knowledge_graph(kg, "my_graph.cypher", format="cypher")

```

This dispatcher is the same function used by Semantica's CLI and MCP tooling.

## MCP Integration: The `export_graph` Tool

The export framework exposes all functionality through the **Model Context Protocol** via [`mcp/tools/export.py`](https://github.com/semantica-agi/semantica/blob/main/mcp/tools/export.py) (lines 24–88). The `handle_export_graph` function:

1. Parses the `format` argument from the MCP request
2. Instantiates the matching exporter class
3. Returns string payloads for text formats (`json`, `csv`, `turtle`) or file paths for binary formats (`parquet`, `cypher`)

This enables remote knowledge graph export through any MCP-compatible client.

## Complete Workflow Example

```python
from semantica.export.methods import export_knowledge_graph

kg = {
    "entities": [
        {"id": "org_1", "type": "Organization", "name": "Acme Corp", "founded": 1950},
        {"id": "per_1", "type": "Person", "name": "Jane Doe", "role": "CEO"},
    ],
    "relationships": [
        {"source_id": "per_1", "target_id": "org_1", "type": "EMPLOYED_BY", "since": 2020}
    ]
}

# Three exports from the same KG

export_knowledge_graph(kg, "corp.ttl", format="turtle")           # RDF

export_knowledge_graph(kg, "corp_analytics", format="parquet")    # Analytics

export_knowledge_graph(kg, "corp_import.cypher", format="cypher") # Graph DB

```

## Summary

- **Three exporter classes** handle format-specific logic: `RDFExporter`, `ParquetExporter`, `LPGExporter`
- **Unified entry point** via `export_knowledge_graph()` in [`semantica/export/methods.py`](https://github.com/semantica-agi/semantica/blob/main/semantica/export/methods.py) automatically selects the correct exporter
- **MCP integration** through [`mcp/tools/export.py`](https://github.com/semantica-agi/semantica/blob/main/mcp/tools/export.py) enables remote export operations
- **Validation layer** ensures output quality: RDF syntax checking, Arrow schema compliance, Cypher identifier sanitization
- **Progress tracking** is built into all exporters via `get_progress_tracker()`

## Frequently Asked Questions

### What RDF formats does Semantica support?

Semantica's `RDFExporter` supports Turtle, RDF/XML, JSON-LD, N-Triples, and N3. Pass the format as the `format` parameter to `export_to_rdf()` or `export_knowledge_graph()`. The exporter uses `RDFSerializer` with `NamespaceManager` for proper prefix handling.

### Can I control Parquet compression and schema?

Yes. The `ParquetExporter` accepts a `compression` parameter (`"snappy"`, `"gzip"`, `"brotli"`, `"zstd"`, `"lz4"`) and uses explicit Apache Arrow schemas defined in [`semantica/export/parquet_exporter.py`](https://github.com/semantica-agi/semantica/blob/main/semantica/export/parquet_exporter.py) to ensure type consistency across `entities.parquet` and `relationships.parquet` outputs.

### How do I import the generated Cypher file into Neo4j?

Run the `.cypher` file through Neo4j Browser, `cypher-shell -f kg.cypher`, or the `neo4j-admin database import` tooling. The `LPGExporter` generates standard `CREATE` statements compatible with Neo4j 4.x and 5.x, plus optional indexes if configured via `batch_size` and related parameters.