Skip to content
Snippets Groups Projects
Select Git revision
  • 8de757e6e717ba30625bcc8f225a07a9fb232f7f
  • main default protected
  • f-prefill
  • dev
  • f-docs-pylib
  • f-parse-value
  • f-compare
  • f-string-ids
  • f-217-set-special-property
  • f-filesystem-import
  • f-filesystem-link
  • f-filesystem-directory
  • f-filesystem-core
  • f-filesystem-cleanup
  • f-check-merge-entities
  • f-compare-enid
  • f-select-subproperties
  • v0.18.0
  • v0.17.0
  • v0.16.0
  • v0.15.1
  • v0.15.0
  • v0.14.0
  • v0.13.2
  • v0.13.1
  • v0.13.0
  • linkahead-rename-step-2
  • linkahead-rename-step-1
  • v0.12.0
  • v0.11.2
  • v0.11.1
  • v0.11.0
  • v0.10.0
  • v0.9.0
  • v0.8.0
  • v0.7.4
  • v0.7.3
37 results

pycaosdb_example.py

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    pycaosdb_example.py 1.14 KiB
    #!/usr/bin/env python3
    """A small example to get started with caosdb-pylib.
    
    Make sure that a `pylinkahead.ini` is readable at one of the expected locations.
    """
    
    import random
    
    import caosdb as db
    
    
    def reconfigure_connection():
        """Change the current connection configuration."""
        conf = db.configuration.get_config()
        conf.set("Connection", "url", "https://demo.indiscale.com")
        db.configure_connection()
    
    
    def main():
        """Shows a few examples how to use the CaosDB library."""
        conf = dict(db.configuration.get_config().items("Connection"))
        print("##### Config:\n{}\n".format(conf))
    
        if conf["cacert"] == "/path/to/caosdb.ca.pem":
            print("Very likely, the path the the TLS certificate is not correct, "
                  "please fix it.")
    
        # Query the server, the result is a Container
        result = db.Query("FIND Record").execute()
        print("##### First query result:\n{}\n".format(result[0]))
    
        # Retrieve a random Record
        rec_id = random.choice([rec.id for rec in result])
        rec = db.Record(id=rec_id).retrieve()
        print("##### Randomly retrieved Record:\n{}\n".format(rec))
    
    
    if __name__ == "__main__":
        main()