-
Notifications
You must be signed in to change notification settings - Fork 16
Python API
#Python API
CCDB CLI is actually written in python, thus there are at least 2 ways to interact with CCDB using python.
-
Using CLI-like API. Which resembles using 'ccdb' command
-
Using so called low-level API.
The code looks like this:
context.process_command_line("mkdir /test/testable2 x y z #Some comment")
This python API is what actually under the hood of 'ccdb' command.
Why to use it? - If you ever wanted to create ccdb CLI commands programmatically and run them using subprocess... Then you can just skip subprocess useing this API directly.
Procs:
- As simple as ccdb command but you get exceptions and don't have to use syscall
- Documentation from ccdb command works here too
- It is safe as ccdb command
Cons:
- You don't get results as python objects. (So, in example, you can't read table names and do
for
on them)
The code looks like this:
tables = provider.get_type_tables("/test/test_vars")
for table in tables:
print(table.name)
It is called "Low-level" to highlight that it becomes possible to screw up data using this API. Why to use it?- you work with python objects that represent CCDB structure. You can iterate them, go from one to another, etc. You can add custom data here, massively change or delete data, etc. Still, if you just readout data, you can't screw up anything.
Procs:
- Full access to CCDB data through python
- Working with python objects
- SQLAlchemy querries to DB are possible
Cons:
- One can screw up data layout. Especially on delete operations (so please, follow instructions and examples, make backups!)
- More complex
Read next: CLI-like API | Low Level API