Skip to main content

NSSurge HTTP API for Python

Project description

NSSurge Python API Client

Python implementation of the Surge HTTP API spec 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.

If you're looking for a command line tool to interact with your running Surge app, check out NSSurge CLI.

Installation

pip

$ pip install nssurge-api

Usage

# 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 asyncio

async 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nssurge_api-0.2.17.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

nssurge_api-0.2.17-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file nssurge_api-0.2.17.tar.gz.

File metadata

  • Download URL: nssurge_api-0.2.17.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.11.3 Darwin/22.5.0

File hashes

Hashes for nssurge_api-0.2.17.tar.gz
Algorithm Hash digest
SHA256 0ac9f517f7bc57dd2dcea55747d9d35bce1cfb42e4f2dcddea69bc399c2bc484
MD5 6eb98504fb5b121f3fb40a021fa93f55
BLAKE2b-256 e249e67df2df5fe47d4a9afd5a586a621cf3f1a6f6a3630047daedf00f55acf9

See more details on using hashes here.

File details

Details for the file nssurge_api-0.2.17-py3-none-any.whl.

File metadata

  • Download URL: nssurge_api-0.2.17-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.11.3 Darwin/22.5.0

File hashes

Hashes for nssurge_api-0.2.17-py3-none-any.whl
Algorithm Hash digest
SHA256 cc83a9a4042b6d1aac8bb4ff30f0e0f534525f09c2c7b035ca56e32391801f11
MD5 d94f061152deb66527c589472ee74704
BLAKE2b-256 d42fdd9e8537ccee1561236a5c5077957992fa1b0168c7f65641d951d928bc14

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page