Skip to content
Snippets Groups Projects
Commit 74d22ae7 authored by Daniel's avatar Daniel
Browse files

DOC: Added ini and python script example.

parent 77d72d60
No related branches found
No related tags found
No related merge requests found
# 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
#!/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()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment