diff --git a/examples/pycaosdb.ini b/examples/pycaosdb.ini new file mode 100644 index 0000000000000000000000000000000000000000..2a5b477d3ddcae562eea3a0a2e2d88122c01ee37 --- /dev/null +++ b/examples/pycaosdb.ini @@ -0,0 +1,22 @@ +# To be found be the caosdb package, the INI file must be located either in +# - $CWD/pycaosdb.ini +# - $HOME/.pycaosdb.ini +# - the location given in the env variable PYCAOSDBINI + +[Connection] +cacert=/path/to/caosdb.ca.pem +url=https://localhost:10443/ +username=admin + +## optional: password in plain text +password_method=plain +password=caosdb + +## OR: password using "pass" password manager +# password_method=pass +# password_identifier=... + +## OR: using the system keyring/wallet (macOS, GNOME, KDE, Windows) +## requires installation of the keyring python package: +## pip install keyring +# password_method=keyring diff --git a/examples/pycaosdb_example.py b/examples/pycaosdb_example.py new file mode 100755 index 0000000000000000000000000000000000000000..5801ea0eb839804ddfb1467f6ca960d954ee3f8b --- /dev/null +++ b/examples/pycaosdb_example.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 +"""A small example to get started with caosdb-pylib. + +Make sure that a `pycaosdb.ini` is readable at one of the expected locations. +""" + +import random + +import caosdb + + +def main(): + """Shows a few examples how to use the CaosDB library.""" + conf = dict(caosdb.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 = caosdb.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 = caosdb.Record(id=rec_id).retrieve() + print("##### Randomly retrieved Record:\n{}\n".format(rec)) + + +if __name__ == "__main__": + main()