# Namespaces and CURIEs Compact `prefix:local` predicates keep models readable and produce Turtle `PREFIX` lines when you serialize the graph. ## Declare prefixes on the model ```python from triplemodel.vocab import FOAF class Person(TripleModel): class Rdf: namespace = "http://example.org/people/" type_uri = f"{FOAF}Person" id_field = "slug" prefixes = {"foaf": str(FOAF)} slug: str name: str = rdf_field("foaf:name") nick: list[str] = rdf_field("foaf:nick", default_factory=list) ``` `list[str]` maps to an **`rdf:List`**, not multiple `foaf:nick` triples. Use `set[str]` for several objects on one predicate — see {doc}`09-rdf-lists-and-lang`. On `to_graph()` / module-level `model_to_graph()` / `sync_to_graph()` with a **new** graph, prefixes are bound automatically when `bind=True` (default for sync on empty graphs). Instance `sync_to_graph()` does not take `bind=`; use module-level `sync_to_graph(..., bind=False)` when needed. ## CURIE expansion Module helper: ```{literalinclude} ../../examples/doc/snippets/mapping_expand_curie.py :language: python ``` Output: ```{literalinclude} ../../examples/doc/outputs/mapping_expand_curie.txt :language: text ``` Absolute IRIs pass through unchanged. Unknown prefixes raise `ValueError`. ## Turtle output ```python graph = person.to_graph() ttl = graph.serialize(format="turtle") # PREFIX foaf: ... ``` For file round-trips, prefer `person.serialize(format="turtle")` and `Person.parse_file("person.ttl")` — see {doc}`10-file-io`. ## Manual bind on an existing graph ```python from triplemodel import bind_namespaces bind_namespaces(graph, {"foaf": "http://xmlns.com/foaf/0.1/"}, strategy="core") ``` | `strategy` | Effect | |------------|--------| | `"core"` | `graph.bind(prefix, namespace)` for each entry | | `"none"` | No-op | Pass `bind=False` to module-level `sync_to_graph` or `model_to_graph` when merging into a graph that already has prefix bindings. ## Vocabulary shortcuts ```python from triplemodel.vocab import FOAF, DCTERMS, SKOS, OWL, RDFS, XSD ``` These are bundled namespace helpers so you can write `f"{FOAF}name"` in full-IRI form and still add `prefixes = {"foaf": str(FOAF)}` for CURIE fields. **Next:** [Custom literals →](07-custom-literals-and-types.md)