Skip to main content

This is a python client sdk for accessing semantha (the semantic platform)

Project description

semantha® SDK

The semantha SDK is a high-level REST client to access the semantha API. The SDK is still under development. An overview of the current progress (i.e. implemented and tested resources and endpoints) may be found at the end of this document (State of Development). The semantha SDK is compatible with python >= 3.8.

Design guideline/idea

Every api call can easily be translated into a python sdk call: GET /api/info -> api.info.get() The SDK offers type hints and doc strings for services, parameters, input types and return types within your IDE.

Disclaimer

IMPORTANT: The SDK is still under development and interfaces may change at any time without notice. Use with caution and on own risk.

Update Notes

Version 5.2.0

The SDK is now automatically generated from our openapi.json specification. It covers 71/169 (=42%) of all available services. Many class names and package names have been changed.

Version 4.5.0

Major restructuring of the SDK. All sub-resources are directly accessible (instead of invoking getters). That also means that (except for a few) all functions are plain get/post/delete/put/patch. For example, in Versions < 4.5.0 a domain resource was fetched using semantha_sdk.domains.get_one("domain_name"). Starting with 4.5.0 it is semantha_sdk.domains("domain_name"). That also means that get/post/put/patch functions return semantha model objects (and never resources), which makes usage more consistent.

Access

To access semantha's API you will need an API and a server url. Both can be requested via this contact form.

Example Usage

Authentication with key

import semantha_sdk
api = semantha_sdk.login(server_url="<semantha platform server URL>", key="<your key>")
print("Talking to semantha server: " + api.info.get().version)

Authentication with key file

import semantha_sdk
api = semantha_sdk.login(server_url="<semantha platform server URL>", key_file="<path to your key file (json format)>")
# end-points (resp. resources) can be used like objects
my_domain = api.domains("my_domain")
# they may have sub-resources, which can be retrieved as objects as well
reference_documents = my_domain.referencedocuments
# GET all reference documents
print("Library contains "+ len(reference_documents.get()) + " entries")

CRUD on End-points

# CRUD operations are functions
domain_settings = my_domain.settings.get()
#Warning: this deletes ALL reference documents/library entries
my_domain.referencedocuments.delete() 

Function Return Types & semantha Data Model

# some functions only return None, e.g.
my_domain.referencedocuments.delete() # returns NoneType

# others return built in types, e.g
roles_list = currentuser.roles.get() # returns List[str]

# but most return objects of the semantha Data Model
# (all returned objects are instances of frozen dataclasses)
settings = my_domain.settings.get() # returns instance of Settings
# attributes can be accessed as properties, e.g.
settings.enable_tagging # returns true or false
# Data Model objects may be complex
document = my_domain.references.post(file=a, referencedocument=b) # returns instance of Document
# the following returns the similarity value of the first references of the first sentence of the
# the first paragraph on the first page of the document (if a reference was found for this sentence)
similarity = pages[0].contents[0].paragraphs[0].references[0].similarity # returns float

State of Development

The following resources and end-points are fully functional and (partially) tested:

  • login -> API
    • .currentuser -> CurrentUser
      • get -> CurrentUser
      • roles -> RolesEndpoint
        • get -> List[str]
    • .diff -> Diff
      • post -> List[Difference]
    • .info -> InfoEndpoint
      • get -> Info
    • .languages -> List[str]
    • .domains -> Domains
      • get -> List[Domain]
    • .domains("domain_name") -> Domain
      • .documentannotations -> DocumentAnnotationsEndpoint
        • post -> IOBase
      • .documentclasses -> DocumentclassesEndpoint
        • get -> List[DocumentClass]
        • post -> DocumentClass
        • delete -> None
      • .documentclasses("id") -> DocumentclassEndpoint
        • get -> DocumentClass(
        • delete -> None
        • put -> DocumentClass
        • documentclasses ->
          • get -> List[DocumentClass]
          • post -> DocumentClass
        • referencedocuments -> ReferencedocumentsEndpoint
          • get -> List[Document]
          • patch -> None
          • delete -> None
      • .documentcomparisons -> DocumentcomparisonsEndpoint
        • post ->
        • .documents -> DocumentsEndpoint
          • post -> List[Document]
      • .modelinstances -> ModelInstance
      • .modelclasses -> ModelClass
      • .referencedocuments -> ReferenceDocuments
        • get -> ReferenceDocuments
        • delete -> None
        • post -> list[DocumentInformation]
        • .clusters -> DocumentCluster
          • get -> DocumentCluster
        • .statistic -> Statistics
          • get -> Statistic
        • .namedentities -> NamedEntities
          • get -> Optional[NamedEntities]
      • .referencedocuments("id") -> ReferenceDocument
        • get -> Document
        • delete -> None
        • patch -> DocumentInformation
        • .paragraphs("id") -> ReferenceDocumentParagraph
          • get -> Paragraph
          • patch -> Paragraph
          • delete -> None
        • .sentences("id") -> ReferenceDocumentSentence
          • get -> Sentence
      • .references -> References
        • post -> Document
      • .settings -> DomainSettings
        • get -> DomainSettings
        • patch -> DomainSettings
      • .similaritymatrix -> List[MatrixRow]
        • .clusters -> List[MatrixRow]
      • .tags -> DomainTags
        • get -> list[str]
        • .("tag").referencedocuments
          • get
          • delete
      • .validation -> SemanticModel
    • .model
      • .domains("domain_name")
        • .boostwords -> Boostwords
          • get -> list[Boostword]
          • delete -> None
          • post_word -> Boostword
          • post_regex -> Boostword
        • .boostwords("id") -> Boostword
          • get -> Boostword
          • delete -> None
          • put_word -> Boostword
          • put_regex -> Boostword
        • .synonyms -> Synonyms
          • get -> list[Synonym]
          • delete -> None
          • post_word -> Synonym
          • post_regex -> Synonym
        • .synonyms("id") -> Synonym
          • get -> Synonym
          • delete -> None
          • put_word -> Synonym
          • put_regex -> Synonym
        • .datatypes -> list[str]

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

semantha_sdk-5.2.0.tar.gz (39.0 kB view hashes)

Uploaded Source

Built Distribution

semantha_sdk-5.2.0-py3-none-any.whl (96.4 kB view hashes)

Uploaded Python 3

Supported by

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