GithubHelp home page GithubHelp logo

praveen-baby / sysrepo-python Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sysrepo/sysrepo-python

0.0 0.0 0.0 125 KB

Python bindings for sysrepo

License: BSD 3-Clause "New" or "Revised" License

Python 91.83% C 5.73% Shell 2.29% Makefile 0.15%

sysrepo-python's Introduction

sysrepo-python

Python CFFI bindings to sysrepo.

pypi-project python-versions build-status license code-style

Installation

pip install sysrepo

This assumes that libsysrepo.so is installed on the system and that sysrepo.h is available in the system include dirs.

Since sysrepo depends on libyang, the latter needs to be installed on the system as well.

You need the following system dependencies installed:

  • Python development headers
  • GCC
  • Python CFFI module

On a Debian/Ubuntu system:

apt-get install python3-dev gcc python3-cffi

Compilation Flags

If sysrepo headers and libraries are installed in a non-standard location, you can export the SYSREPO_HEADERS and SYSREPO_LIBRARIES variables. Additionally, for finer control, you may use SYSREPO_EXTRA_CFLAGS and SYSREPO_EXTRA_LDFLAGS:

SYSREPO_HEADERS=/home/build/opt/sr/include \
SYSREPO_LIBRARIES=/home/build/opt/sr/lib \
SYSREPO_EXTRA_CFLAGS="-O3" \
SYSREPO_EXTRA_LDFLAGS="-Wl,-rpath=/opt/sr/lib" \
        pip install sysrepo

Note

This Python package depends on libyang CFFI bindings, if it is not installed yet and libyang headers and libraries are also installed in a non-standard location, you must export additional variables. See the "Compilation Flags" section here: https://pypi.org/project/libyang/.

Examples

Module Config Replacement

with sysrepo.SysrepoConnection() as conn:
    with conn.start_session() as sess:
        sess.replace_config({"system": {"hostname": "foobar"}}, "my-module")

Operational Data Request

with sysrepo.SysrepoConnection() as conn:
    with conn.start_session("operational") as sess:
        data = sess.get_data("/my-module:status")

RPC Call

with sysrepo.SysrepoConnection() as conn:
    with conn.start_session() as sess:
        out = sess.rpc_send("/my-module:my-rpc", {"input-param": 42})

Subscription

with sysrepo.SysrepoConnection() as conn:
    with conn.start_session() as sess:
        sess.subscribe_module_change("my-module", None, module_change_cb)
        sess.subscribe_oper_data_request(
            "my-module", "/my-module:status", oper_data_cb)
        sess.subscribe_rpc_call("/my-module:my-rpc", my_rpc_cb)

See the examples/ folder for more details.

Differences With libsysrepo.so C API

This project has been created with Python users in mind. In order to get a more pythonic API there are significant divergences with the C API.

Supported Features

  • Connection handling (sr_connect(), sr_disconnect())
  • YANG modules management (sr_install_module(), sr_remove_module())
  • libyang context retrieval (sr_get_context() wrapped using the libyang CFFI bindings).
  • Session management (sr_session_start(), sr_session_stop(), sr_session_switch_ds(), sr_session_get_ds(), sr_unsubscribe())
  • Module change subscriptions (sr_module_change_subscribe() also with async callbacks, sr_get_changes_iter()).
  • Operational data subscriptions (sr_oper_get_items_subscribe() also with async callbacks).
  • RPC/action call subscriptions (sr_rpc_subscribe_tree() also with async callbacks).
  • RPC/action calling (sr_rpc_send_tree())
  • Datastore edition (sr_set_item_str(), sr_delete_item(), sr_edit_batch(), sr_validate(), sr_apply_changes(), sr_discard_changes(), sr_replace_config())
  • Get data (sr_get_data(), sr_get_item(), sr_get_items())

Not Yet Supported Features

All other features are not yet supported by sysrepo-python. The most notable are:

  • Notification support (sr_event_notif_*)
  • Module locking (sr_*lock*)
  • Module management (sr_*_module_*)

Contributing

This is an open source project and all contributions are welcome.

See the CONTRIBUTING.rst file for more details.

sysrepo-python's People

Contributors

rjarry avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.