Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tddschn/nssurge-api
NSSurge HTTP API for Python
https://github.com/tddschn/nssurge-api
aiohttp api api-client api-wrapper nssurge python surge surge-http-api surge-module surge4 surge5
Last synced: 2 months ago
JSON representation
NSSurge HTTP API for Python
- Host: GitHub
- URL: https://github.com/tddschn/nssurge-api
- Owner: tddschn
- License: mit
- Created: 2022-05-13T09:12:42.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-07-20T16:28:11.000Z (over 1 year ago)
- Last Synced: 2024-08-10T20:34:12.597Z (5 months ago)
- Topics: aiohttp, api, api-client, api-wrapper, nssurge, python, surge, surge-http-api, surge-module, surge4, surge5
- Language: Python
- Homepage: https://pypi.org/project/nssurge-api/
- Size: 135 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# NSSurge Python API Client
Python implementation of the [Surge HTTP API spec](https://manual.nssurge.com/others/http-api.html) client using `aiohttp`.
You can use it to get/set Surge rules / policies / proxy groups, get recent requests / events and much more.
This projects fully implements the [Surge HTTP API spec](https://manual.nssurge.com/others/http-api.html).
If you're looking for a command line tool to interact with your running Surge app, check out [NSSurge CLI](https://github.com/tddschn/nssurge-cli).
- [NSSurge Python API Client](#nssurge-python-api-client)
- [Installation](#installation)
- [pip](#pip)
- [Usage](#usage)
- [Develop](#develop)
- [See also](#see-also)## Installation
### [pip](https://pypi.org/project/nssurge-api/)
```
$ pip install nssurge-api
```## Usage
```python
# source: https://github.com/tddschn/nssurge-cli/blob/master/nssurge_cli/cap_commands.py
from nssurge_cli.types import OnOffToggleEnum
from nssurge_api import SurgeAPIClient
from nssurge_api.types import Capability
import asyncioasync def get_set_cap(
capability: Capability, on_off: OnOffToggleEnum | None = None
) -> bool | tuple[bool, bool]:
"""
Get or set a capability
"""
async with SurgeAPIClient(*get_config()) as client:
state_orig = await get_cap_state(client, capability)
match on_off:
case OnOffToggleEnum.on | OnOffToggleEnum.off:
await client.set_cap(capability, s2b(on_off))
case OnOffToggleEnum.toggle:
await client.set_cap(capability, not state_orig)
case _:
return state_orig
state_new = await get_cap_state(client, capability)
return state_orig, state_new
```## Develop
```
$ git clone https://github.com/tddschn/nssurge-api.git
$ cd nssurge-api
$ poetry install
```## See also
- [NSSurge CLI](https://github.com/tddschn/nssurge-cli): Command line Surge HTTP API Client built with this library
- [Surge HTTP API spec](https://manual.nssurge.com/others/http-api.html)