Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-pylib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-pylib
Commits
74d22ae7
Commit
74d22ae7
authored
5 years ago
by
Daniel
Browse files
Options
Downloads
Patches
Plain Diff
DOC: Added ini and python script example.
parent
77d72d60
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/pycaosdb.ini
+22
-0
22 additions, 0 deletions
examples/pycaosdb.ini
examples/pycaosdb_example.py
+31
-0
31 additions, 0 deletions
examples/pycaosdb_example.py
with
53 additions
and
0 deletions
examples/pycaosdb.ini
0 → 100644
+
22
−
0
View file @
74d22ae7
# 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
This diff is collapsed.
Click to expand it.
examples/pycaosdb_example.py
0 → 100755
+
31
−
0
View file @
74d22ae7
#!/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
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment