Skip to content
Dmitry Romanov edited this page Nov 30, 2015 · 17 revisions

#Python API

CCDB CLI is actually written in python, thus there are at least 2 ways to interact with CCDB using python.

  1. Using CLI-like API. Which resembles using 'ccdb' command

  2. Using so called low-level API.

Using 'ccdb' command like functions:

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)

Using Low Level python API

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