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-1.0.1.tar.gz (82.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: nssurge_api-1.0.1.tar.gz
  • Upload date:
  • Size: 82.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for nssurge_api-1.0.1.tar.gz
Algorithm Hash digest
SHA256 498a3efcd7eb0cbdbe029f89cf3695a31842fd1413e15b3d017ee4f9bda89be0
MD5 cd660b47a97c83af581295f1d0c010a6
BLAKE2b-256 e4f81093e92b36b5c697f03f26323c80ca073caa4aa69edffc31fa649aa52408

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nssurge_api-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for nssurge_api-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f7081f71b74e961a47f03c4517684817a558d6b29c2ee37cff76261ae50a1397
MD5 fdb3c8e59646a13515d0cccca8e8ed33
BLAKE2b-256 13f3d32e3f93587b0b027d872263126f19be1d64d8cd3ed5db9ef2326184ba53

See more details on using hashes here.

Supported by

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