Skip to main content

Analyze a relational database schema into a conceptual model (OWL-capable) with mapping back to the source schema.

Project description

relational-schema-analyzer

Analyze a relational database schema and produce a canonical conceptual model (entities / relationships / properties), a conceptual → physical mapping back to the source relational schema, and metadata (confidence, fingerprints, patterns). Optional exports include OWL (Turtle / JSON-LD) for ontology pipelines.

This library is the relational analogue of arangodb-schema-analyzer and emits the same tool-contract bundle shape so that downstream consumers (arango-ontoextract, transpilers, and ETL tools such as r2g) can treat relational and ArangoDB sources interchangeably.

PostgreSQL / MySQL / SQL Server / Snowflake / CSV
        │
        ▼  introspect (live catalog views, not DDL parsing)
   Physical Schema  (tables, columns, PKs, FKs, types)
        │
        ▼  infer (deterministic baseline + optional LLM refinement)
   { conceptualSchema, physicalMapping, metadata }   ← canonical JSON bundle
        │
        ├──► OWL Turtle / JSON-LD       (arango-ontoextract, ontology tooling)
        ├──► relational physical view   (SQL-native query tooling, future)
        └──► consumed by r2g            (drives ArangoDB MappingConfig generation)

Status

Early development. Phases 0–3 implemented: the physical core (connectors, types, FK inference) is extracted from r2g; the deterministic conceptual baseline emits a contract-valid {conceptualSchema, physicalMapping, metadata} bundle with no LLM; and OWL (Turtle / JSON-LD) exports + a CLI are in place. Next: optional LLM refinement (Phase 4) and ecosystem integration (Phase 5). See:

from relational_schema_analyzer import (
    create_connector, RelationalSchemaAnalyzer, export_owl_turtle,
)

physical = create_connector("postgresql", url, schema_name="public").get_schema()
analysis = RelationalSchemaAnalyzer().analyze(physical)   # baseline, no LLM
bundle = analysis.to_bundle()    # {conceptualSchema, physicalMapping, metadata}
ttl = export_owl_turtle(analysis)

# Optional LLM refinement (additive; falls back to baseline on any error):
refined = RelationalSchemaAnalyzer(
    llm_provider="openai",           # or "anthropic" / "openrouter" / a provider object
).analyze(physical)                  # better names + embed/n-ary hints
relational-schema-analyzer snapshot --source postgresql --url "$DSN" -o physical.json
relational-schema-analyzer analyze  --from-snapshot physical.json --pretty
relational-schema-analyzer owl      --from-snapshot physical.json --format turtle -o schema.ttl

Sources: postgresql, mysql, sqlserver, snowflake, duckdb, databricks, csv.

MCP server (optional, pip install 'relational-schema-analyzer[mcp]') exposes the same snapshot / analyze / owl operations over the v1 tool contract:

relational-schema-analyzer-mcp                                   # stdio (local IDE)
relational-schema-analyzer-mcp --transport sse --host 0.0.0.0 --port 8000   # remote (set RSA_MCP_TOKEN)

Why this exists

Most of the relational introspection layer already exists and is battle-tested inside the r2g (relational-to-graph) project, but it is welded to ArangoDB ETL and cannot be reused elsewhere. This repo extracts that core into a paradigm-neutral library and adds the conceptual / OWL layer that r2g never had, conforming to the contract the ArangoDB analyzer already publishes.

License

Apache-2.0 — matching the surrounding Arango ecosystem libraries (arangodb-schema-analyzer, r2g). See LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

relational_schema_analyzer-0.1.0.tar.gz (134.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

relational_schema_analyzer-0.1.0-py3-none-any.whl (101.5 kB view details)

Uploaded Python 3

File details

Details for the file relational_schema_analyzer-0.1.0.tar.gz.

File metadata

File hashes

Hashes for relational_schema_analyzer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7522d1e91d68455afeeb3320a674abfd95af23152f54d06e4a86fd4fb28e667d
MD5 17a574c8725c3f0795d68f5d98f90894
BLAKE2b-256 816ba444a7739143dfdb2bd6384ed8e650693a0768cdf83bb4e62cb9af4e59ec

See more details on using hashes here.

File details

Details for the file relational_schema_analyzer-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for relational_schema_analyzer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1aac150a79b2ab0fc4d64f6f43f86e27474c82fddf2f5693ab063a4f8ef8e4d1
MD5 b32c10eb9c1aca5562219a9f7ee956b1
BLAKE2b-256 b169e2748941e0ca9404a10d0480301340995bf1f6606df87a00ad234972f1f1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page