{"id":43011224,"url":"https://github.com/edwardanderson/rdfs_pydantic","last_synced_at":"2026-01-31T05:30:33.995Z","repository":{"id":334700744,"uuid":"1142384038","full_name":"edwardanderson/rdfs_pydantic","owner":"edwardanderson","description":"Create Pydantic models from RDFS ontologies","archived":false,"fork":false,"pushed_at":"2026-01-26T22:24:24.000Z","size":147,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-27T00:36:50.721Z","etag":null,"topics":["rdfs"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/edwardanderson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-01-26T10:41:02.000Z","updated_at":"2026-01-26T22:24:28.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/edwardanderson/rdfs_pydantic","commit_stats":null,"previous_names":["edwardanderson/rdfs_pydantic"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/edwardanderson/rdfs_pydantic","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edwardanderson%2Frdfs_pydantic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edwardanderson%2Frdfs_pydantic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edwardanderson%2Frdfs_pydantic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edwardanderson%2Frdfs_pydantic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/edwardanderson","download_url":"https://codeload.github.com/edwardanderson/rdfs_pydantic/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edwardanderson%2Frdfs_pydantic/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28930355,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-31T04:05:25.756Z","status":"ssl_error","status_checked_at":"2026-01-31T04:02:35.005Z","response_time":128,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rdfs"],"created_at":"2026-01-31T05:30:33.422Z","updated_at":"2026-01-31T05:30:33.986Z","avatar_url":"https://github.com/edwardanderson.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RDFS Pydantic\n\nCreate [Pydantic](https://docs.pydantic.dev/latest/) models from [RDFS](https://www.w3.org/TR/rdf-schema/) ontologies.\n\n\u003e [!CAUTION]\n\u003e Experimental\n\n## Features\n\n- **Module generation**: Generate Python code as a single module containing all classes\n- **Package generation**: Create file-based package structures with a module for each class\n- **JSON-LD aliasing**: Use a `@context` document to customise class and property names\n- **Inheritance support**: RDFS `rdfs:subClassOf` becomes Python inheritance\n- **Union types**: Multiple property ranges become union types\n- **Namespace handling**: Automatic disambiguation for classes with identical names across namespaces\n- **Doctrings**: Single- and multi-line docstrings are generated from the IRI, `rdfs:label` and `rdfs:comment` values\n\n## Quick Start\n\nHere's an example RDFS ontology using simple artist and artwork classes.\n\n```turtle\n@prefix ex: \u003chttp://example.org/\u003e .\n@prefix rdf: \u003chttp://www.w3.org/1999/02/22-rdf-syntax-ns#\u003e .\n@prefix rdfs: \u003chttp://www.w3.org/2000/01/rdf-schema#\u003e .\n\nex:Agent a rdfs:Class ;\n    rdfs:comment \"A person or organisation\" .\n\nex:Artist a rdfs:Class ;\n    rdfs:subClassOf ex:Agent ;\n    rdfs:comment \"A creator of artworks\" .\n\nex:Artwork a rdfs:Class ;\n    rdfs:comment \"An artistic creation\" .\n\nex:Painting a rdfs:Class ;\n    rdfs:subClassOf ex:Artwork .\n\nex:Exhibition a rdfs:Class ;\n    rdfs:comment \"A curated collection of artworks\" .\n\nex:name a rdf:Property ;\n    rdfs:domain ex:Agent ;\n    rdfs:range rdfs:Literal .\n\nex:created a rdf:Property ;\n    rdfs:domain ex:Artist ;\n    rdfs:range ex:Painting .\n\nex:artist a rdf:Property ;\n    rdfs:domain ex:Artwork ;\n    rdfs:range ex:Artist .\n\nex:artworks a rdf:Property ;\n    rdfs:domain ex:Exhibition ;\n    rdfs:range ex:Painting , ex:Artwork .\n```\n\nGenerate the Pydantic models from the ontology.\n\n```python\nfrom rdflib import Graph\nfrom rdfs_pydantic import create_module\n\ng = Graph()\ng.parse(\"path/to/ontology.ttl\", format=\"turtle\")\npydantic_code = create_module(g)\nprint(pydantic_code)\n```\n\nResult:\n\n```python\nfrom __future__ import annotations\nfrom pydantic import BaseModel\n\n\nclass Agent(BaseModel):\n    \"\"\"\u003chttp://example.org/Agent\u003e.\n\n    A person or organisation.\n    \"\"\"\n    name: str | list[str] | None = None\n\n\nclass Artist(Agent):\n    \"\"\"\u003chttp://example.org/Artist\u003e.\n\n    A creator of artworks.\n    \"\"\"\n    created: Painting | list[Painting] | None = None\n\n\nclass Artwork(BaseModel):\n    \"\"\"\u003chttp://example.org/Artwork\u003e.\n\n    An artistic creation.\n    \"\"\"\n    artist: Artist | list[Artist] | None = None\n\n\nclass Exhibition(BaseModel):\n    \"\"\"\u003chttp://example.org/Exhibition\u003e.\n\n    A curated collection of artworks.\n    \"\"\"\n    artworks: Painting | Artwork | list[Painting | Artwork] | None = None\n\n\nclass Painting(Artwork):\n    \"\"\"\u003chttp://example.org/Painting\u003e.\"\"\"\n    ...\n```\n\n## Module \u0026 Package Generation\n\n### Module Generation\n\nGenerate all models as a single Python string, suitable for dynamic evaluation or single-file output:\n\n```python\nfrom rdflib import Graph\nfrom rdfs_pydantic import create_module\n\ng = Graph()\ng.parse(\"ontology.ttl\", format=\"turtle\")\ncode = create_module(g)\nprint(code)\n```\n\n### Package Generation\n\nCreate a structured package directory with separate files per class:\n\n```python\nfrom rdflib import Graph\nfrom rdfs_pydantic import create_package\n\ng = Graph()\ng.parse(\"ontology.ttl\", format=\"turtle\")\ncreate_package(g, output_dir=\"my_ontology_package\")\n```\n\n## JSON-LD Aliasing\n\nProvide a JSON-LD `@context` to rename classes and properties:\n\n```python\nfrom rdflib import Graph\nfrom rdfs_pydantic import create_module\n\ng = Graph()\ng.parse(data=\"\"\"\n    @prefix rdfs: \u003chttp://www.w3.org/2000/01/rdf-schema#\u003e .\n    \u003chttp://example.org/E1\u003e a rdfs:Class .\n\"\"\", format=\"turtle\")\n\ncontext = {\n    \"@context\": {\n        \"Entity\": {\"@id\": \"http://example.org/E1\"}\n    }\n}\n\ncode = create_module(g, context=context)\n# Generates: class Entity(BaseModel): ...\n```\n\n## CLI\n\n```bash\n# Generate module to stdout\nuv run rdfs_pydantic module --ontology ontology.ttl\n\n# Generate package structure\nuv run rdfs_pydantic package --ontology ontology.ttl --output-dir ./output\n```\n\n## Test\n\n```bash\nuv run pytest\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedwardanderson%2Frdfs_pydantic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fedwardanderson%2Frdfs_pydantic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedwardanderson%2Frdfs_pydantic/lists"}