Skip to content

Commit 8fd4376

Browse files
committed
Initial commit
0 parents  commit 8fd4376

19 files changed

+2321
-0
lines changed

.github/workflows/ci.yaml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
max-parallel: 10
10+
matrix:
11+
python: ["3.10", "3.11", "3.12"]
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
- name: Set up python ${{ matrix.python }}
16+
uses: actions/setup-python@v4
17+
with:
18+
python-version: ${{ matrix.python }}
19+
- name: Setup dev env
20+
run: |
21+
python -m pip install --upgrade pip
22+
python -m pip install --upgrade setuptools wheel
23+
python -m pip install .[dev]
24+
- name: Run ruff format
25+
run: ruff format .
26+
- name: Run ruff
27+
run: ruff check .
28+
29+
test:
30+
runs-on: ubuntu-latest
31+
steps:
32+
- name: Checkout
33+
uses: actions/checkout@v4
34+
- name: Set up python 3.10
35+
uses: actions/setup-python@v4
36+
with:
37+
python-version: "3.10"
38+
- name: Setup dev env
39+
run: |
40+
python -m pip install --upgrade pip
41+
python -m pip install --upgrade setuptools wheel
42+
python -m pip install .[test]
43+
- name: Run test
44+
run: pytest

.github/workflows/publish.yaml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Publish
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
deploy:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
- uses: actions/setup-python@v4
13+
with:
14+
python-version: "3.10"
15+
- name: Setup publish env
16+
run: |
17+
python -m pip install --upgrade pip
18+
python -m pip install .[publish]
19+
- name: Build
20+
run: python -m build
21+
- name: Check
22+
run: python -m twine check dist/*
23+
- name: Publish
24+
env:
25+
TWINE_USERNAME: __token__
26+
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
27+
run: python -m twine upload dist/*

.gitignore

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
env/
12+
build/
13+
develop-eggs/
14+
dist/
15+
downloads/
16+
eggs/
17+
.eggs/
18+
lib/
19+
lib64/
20+
parts/
21+
sdist/
22+
var/
23+
wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
28+
# PyInstaller
29+
# Usually these files are written by a python script from a template
30+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
31+
*.manifest
32+
*.spec
33+
34+
# Installer logs
35+
pip-log.txt
36+
pip-delete-this-directory.txt
37+
38+
# Unit test / coverage reports
39+
htmlcov/
40+
.tox/
41+
.coverage
42+
.coverage.*
43+
.cache
44+
nosetests.xml
45+
coverage.xml
46+
*.cover
47+
.hypothesis/
48+
.pytest_cache/
49+
50+
# Translations
51+
*.mo
52+
*.pot
53+
54+
# Django stuff:
55+
*.log
56+
local_settings.py
57+
58+
# Flask stuff:
59+
instance/
60+
.webassets-cache
61+
62+
# Scrapy stuff:
63+
.scrapy
64+
65+
# Sphinx documentation
66+
docs/_build/
67+
68+
# PyBuilder
69+
target/
70+
71+
# Jupyter Notebook
72+
.ipynb_checkpoints
73+
74+
# pyenv
75+
.python-version
76+
77+
# celery beat schedule file
78+
celerybeat-schedule
79+
80+
# SageMath parsed files
81+
*.sage.py
82+
83+
# env files
84+
.env
85+
86+
# virtualenv
87+
.venv
88+
venv/
89+
ENV/
90+
91+
# Spyder project settings
92+
.spyderproject
93+
.spyproject
94+
95+
# Rope project settings
96+
.ropeproject
97+
98+
# mkdocs documentation
99+
/site
100+
101+
# mypy
102+
.mypy_cache/
103+
104+
# IDE settings
105+
.vscode/
106+
.idea/
107+
*.code-workspace
108+
109+
# ruff
110+
.ruff_cache

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Artem Kotik
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# aiogNMI
2+
3+
## About
4+
5+
This Python library provides an efficient and lightweight gNMI client implementation that leverages asynchronous approach.
6+
7+
### Supported RPCs:
8+
9+
* Capabilities
10+
* Get
11+
* Set
12+
* Subscribe (under development)
13+
14+
### Tested on:
15+
16+
* Arista EOS
17+
* Nokia SR OS
18+
19+
Repository contains protobuf files from [gNMI](https://github.com/openconfig/gnmi/tree/master/proto) repo and based on gNMI release v0.10.0.
20+
Early gNMI version should work too, I've tested with 0.7.0 and it works well.
21+
22+
> **_NOTE:_** At this moment supporting of the secure connections (with encryption or certificate) is in alpha version. You can use them, but I don't guarantee stable work.
23+
24+
## Install
25+
26+
Install with pip:
27+
28+
```bash
29+
pip install aiognmi
30+
```
31+
32+
## Examples
33+
34+
`Capabilities` RPC
35+
36+
```python
37+
import asyncio
38+
39+
from aiognmi import AsyncgNMIClient
40+
41+
42+
async def main():
43+
async with AsyncgNMIClient(host="test-1", port=6030, username="admin", password="admin", insecure=True) as client:
44+
resp = await client.get_capabilities()
45+
46+
print(resp.result)
47+
48+
49+
if __name__ == "__main__":
50+
asyncio.run(main())
51+
```
52+
53+
`Get` RPC
54+
55+
```python
56+
import asyncio
57+
58+
from aiognmi import AsyncgNMIClient
59+
60+
61+
async def main():
62+
async with AsyncgNMIClient(host="test-1", port=6030, username="admin", password="admin", insecure=True) as client:
63+
resp = await client.get(
64+
paths=[
65+
"/interfaces/interface[name=Management0]",
66+
]
67+
)
68+
69+
print(resp.result)
70+
71+
72+
if __name__ == "__main__":
73+
asyncio.run(main())
74+
```
75+
76+
`Set` RPC
77+
78+
```python
79+
import asyncio
80+
81+
from aiognmi import AsyncgNMIClient
82+
83+
84+
async def main():
85+
async with AsyncgNMIClient(host="test-1", port=6030, username="admin", password="admin", insecure=True) as client:
86+
resp = await client.set(
87+
update=[
88+
{"path": "/interfaces/interface[name=Management0]/config", "data": {"description": "gnmi update test"}}
89+
]
90+
)
91+
92+
print(resp.result)
93+
94+
95+
if __name__ == "__main__":
96+
asyncio.run(main())
97+
```
98+
99+
## Credits
100+
101+
My work is inspired by these people:
102+
103+
1. [Anton Karneliuk](https://github.com/akarneliuk) and his [pyGNMI](https://github.com/akarneliuk/pygnmi) library
104+
2. [Carl Montanari](https://github.com/carlmontanari) and his [scrapli](https://github.com/carlmontanari/scrapli) library

aiognmi/__init__.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from aiognmi.client import AsyncgNMIClient
2+
3+
__version__ = "0.1.0"
4+
5+
__all__ = ("AsyncgNMIClient",)

0 commit comments

Comments
 (0)