Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use pyang in another python program? #846

Open
rkkilari opened this issue Feb 17, 2023 · 1 comment
Open

How to use pyang in another python program? #846

rkkilari opened this issue Feb 17, 2023 · 1 comment

Comments

@rkkilari
Copy link

Can we use pyang in a python program? Can anyone help providing some links where such an example code is provided. I tried to use pyang to

  1. load yang file
  2. parse it in to statements and ...
  3. traverse the statements and generate angular code templates as per container leaf, leaf-list, ...
@hyberdk
Copy link

hyberdk commented Nov 3, 2023

hi @rkkilari,

I have used the pyang_tool.py as inspiration..

but essentially you need this to get started..

from pyang import statements
from pyang.statements import ModSubmodStatement
from pyang.repository import FileRepository
from pyang.context import Context

repo = FileRepository(path="ios-xe_17.6.5")
ctx = Context(repo)
module: ModSubmodStatement = ctx.read_module("Cisco-IOS-XE-native")
statements.validate_module(ctx, module)

Hope that helps :-)

Esben

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants