Skip to content

create_ontology async

create_ontology(
    name: OntologyName,
    source_format: OntologySourceFormat,
    source: OntologySource,
    *,
    config_overrides: Optional[AsyncContextClientConfig] = None,
    client_token: Optional[ClientToken] = None,
    description: Optional[UserDefinedString] = None,
    tags: Optional[TagMap] = None,
) -> CreateOntologyResponse

Creates an ontology from an OWL ontology document. An ontology defines the types of nodes and edges in an agent context. Returns the new ontology's ID and ARN.

Parameters:

  • client_token (Optional[ClientToken], default: None ) –

    Client idempotency token. A reused token with an identical request returns the existing ontology with no second write. A reused token with a different request (any member differs, for example name, description, sourceFormat, or source) is a ValidationException naming clientToken, never a ConflictException. The AWS SDKs generate the token automatically. A request that arrives without a token is a ValidationException.

  • name (OntologyName) –

    Friendly display name for the ontology (for example, "Sales Org"). AWS Context assigns the ontology its opaque ID. This name is a non-unique label. You can rename the ontology in the AWS Context console.

  • description (Optional[UserDefinedString], default: None ) –

    Optional description of the ontology. Part of the idempotency comparison on a replay.

  • source_format (OntologySourceFormat) –

    The format of source. The only supported value is TURTLE.

  • source (OntologySource) –

    An OWL ontology to derive the template from, in sourceFormat.

  • tags (Optional[TagMap], default: None ) –

    Tags to add to the ontology when you create it: up to 200 in the request, of which at most 50 can be user tags. Keys can't start with aws:. To add tags, you also need context:TagResource permission on the new ontology. If you specify more than 50 user tags, the request fails with ServiceQuotaExceededException, as on TagResource. If an AWS Organizations tag policy refuses a tag, the request fails with ValidationException.

Raises:

  • AccessDeniedException –

    You don't have sufficient access to perform this operation. Verify that you have permission to perform the operation on the resource.

  • InternalServerException –

    The request failed because of an internal error. Retry the request.

  • ThrottlingException –

    The request was denied because it exceeded a request rate quota. Wait, then retry the request.

  • ValidationException –

    The input fails to satisfy the constraints of the operation. Correct the input before you retry the request.

  • ConflictException –

    The request conflicts with the current state of the resource. Check the resource's current state before you retry the request.

  • ServiceQuotaExceededException –

    The request would exceed a service quota. Check the quota that quotaCode names, reduce your usage, and then retry the request.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Examples:

Create an ontology The following example creates an ontology from a Turtle (OWL) document that defines customers, orders, and the relationship between them.

>>> await client.create_ontology(client_token='3f1c9a2e-5b7d-4e8f-9a0b-1c2d3e4f5a6b', name='sales-analytics', description='Customers and the orders they place.', source_format='TURTLE', source='@prefix ex: <http://example.com/sales#> .\n@prefix owl: <http://www.w3.org/2002/07/owl#> .\n@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n\n<http://example.com/sales> a owl:Ontology .\n\nex:Customer a owl:Class ;\n  rdfs:label "Customer" ;\n  rdfs:comment "A person or company that places orders." .\n\nex:Order a owl:Class ;\n  rdfs:label "Order" ;\n  rdfs:comment "A purchase that a customer places." .\n\nex:customerId a owl:DatatypeProperty ;\n  rdfs:domain ex:Customer ;\n  rdfs:range xsd:string .\n\nex:orderId a owl:DatatypeProperty ;\n  rdfs:domain ex:Order ;\n  rdfs:range xsd:string .\n\nex:placedOrder a owl:ObjectProperty ;\n  rdfs:label "placed order" ;\n  rdfs:domain ex:Customer ;\n  rdfs:range ex:Order .\n', tags={'team': 'analytics'})
Source code in docs_src/capo_context/_services/async_context.py
async def create_ontology(
    self,
    name: "capo_context.types.ontology_name.OntologyName",
    source_format: "capo_context.types.ontology_source_format.OntologySourceFormat",
    source: "capo_context.types.ontology_source.OntologySource",
    *,
    config_overrides: Optional[AsyncContextClientConfig] = None,
    client_token: Optional["capo_context.types.client_token.ClientToken"] = None,
    description: Optional[
        "capo_context.types.user_defined_string.UserDefinedString"
    ] = None,
    tags: Optional["capo_context.types.tag_map.TagMap"] = None,
) -> "capo_context.types.create_ontology_response.CreateOntologyResponse":
    r"""<p>Creates an ontology from an OWL ontology document. An ontology defines the types of nodes and edges in an agent context. Returns the new ontology's ID and ARN.</p>

    Args:
        client_token: <p>Client idempotency token. A reused token with an identical request returns the existing ontology with no second write. A reused token with a different request (any member differs, for example <code>name</code>, <code>description</code>, <code>sourceFormat</code>, or <code>source</code>) is a ValidationException naming <code>clientToken</code>, never a ConflictException. The AWS SDKs generate the token automatically. A request that arrives without a token is a ValidationException.</p>
        name: <p>Friendly display name for the ontology (for example, "Sales Org"). AWS Context assigns the ontology its opaque ID. This name is a non-unique label. You can rename the ontology in the AWS Context console.</p>
        description: <p>Optional description of the ontology. Part of the idempotency comparison on a replay.</p>
        source_format: <p>The format of <code>source</code>. The only supported value is <code>TURTLE</code>.</p>
        source: <p>An OWL ontology to derive the template from, in <code>sourceFormat</code>.</p>
        tags: <p>Tags to add to the ontology when you create it: up to 200 in the request, of which at most 50 can be user tags. Keys can't start with <code>aws:</code>. To add tags, you also need <code>context:TagResource</code> permission on the new ontology. If you specify more than 50 user tags, the request fails with <code>ServiceQuotaExceededException</code>, as on TagResource. If an AWS Organizations tag policy refuses a tag, the request fails with <code>ValidationException</code>.</p>

    Raises:
        capo_context.errors.access_denied_exception.AccessDeniedException: <p>You don't have sufficient access to perform this operation. Verify that you have permission to perform the operation on the resource.</p>
        capo_context.errors.internal_server_exception.InternalServerException: <p>The request failed because of an internal error. Retry the request.</p>
        capo_context.errors.throttling_exception.ThrottlingException: <p>The request was denied because it exceeded a request rate quota. Wait, then retry the request.</p>
        capo_context.errors.validation_exception.ValidationException: <p>The input fails to satisfy the constraints of the operation. Correct the input before you retry the request.</p>
        capo_context.errors.conflict_exception.ConflictException: <p>The request conflicts with the current state of the resource. Check the resource's current state before you retry the request.</p>
        capo_context.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: <p>The request would exceed a service quota. Check the quota that <code>quotaCode</code> names, reduce your usage, and then retry the request.</p>
        capo_context.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        Create an ontology
        The following example creates an ontology from a Turtle (OWL) document that defines customers, orders, and the relationship between them.

        >>> await client.create_ontology(client_token='3f1c9a2e-5b7d-4e8f-9a0b-1c2d3e4f5a6b', name='sales-analytics', description='Customers and the orders they place.', source_format='TURTLE', source='@prefix ex: <http://example.com/sales#> .\n@prefix owl: <http://www.w3.org/2002/07/owl#> .\n@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n\n<http://example.com/sales> a owl:Ontology .\n\nex:Customer a owl:Class ;\n  rdfs:label "Customer" ;\n  rdfs:comment "A person or company that places orders." .\n\nex:Order a owl:Class ;\n  rdfs:label "Order" ;\n  rdfs:comment "A purchase that a customer places." .\n\nex:customerId a owl:DatatypeProperty ;\n  rdfs:domain ex:Customer ;\n  rdfs:range xsd:string .\n\nex:orderId a owl:DatatypeProperty ;\n  rdfs:domain ex:Order ;\n  rdfs:range xsd:string .\n\nex:placedOrder a owl:ObjectProperty ;\n  rdfs:label "placed order" ;\n  rdfs:domain ex:Customer ;\n  rdfs:range ex:Order .\n', tags={'team': 'analytics'})
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_context.types.create_ontology_request.CreateOntologyRequest]",
    ) -> AsyncOperationResponse[
        "capo_context.types.create_ontology_response.CreateOntologyResponse"
    ]:
        import capo_context._operations.context.create_ontology

        (
            output,
            http_response,
        ) = await capo_context._operations.context.create_ontology.async_create_ontology(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_context.types.create_ontology_request.CreateOntologyRequest",
    ) -> dict[str, Any]:
        import capo_context.types.create_ontology_request

        return capo_context.types.create_ontology_request.redact_sensitive(input_)

    def _redact_output(
        output: "capo_context.types.create_ontology_response.CreateOntologyResponse",
    ) -> dict[str, Any]:
        import capo_context.types.create_ontology_response

        return capo_context.types.create_ontology_response.redact_sensitive(output)

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "CreateOntology",
            redact_input=_redact_input,
            redact_output=_redact_output,
        ),
    )
    input_: capo_context.types.create_ontology_request.CreateOntologyRequest = {
        "name": name,
        "source_format": source_format,
        "source": source,
    }
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token
    if description is not None:
        input_["description"] = description
    if tags is not None:
        input_["tags"] = tags

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output