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.0.tar.gz (81.4 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.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nssurge_api-1.0.0.tar.gz
  • Upload date:
  • Size: 81.4 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.0.tar.gz
Algorithm Hash digest
SHA256 86e693628ab56ae025743671555f148cd200cac01901f6476f0947dc3a1d06c2
MD5 6326b2e522a9f41bc4d3e64cc1d410e0
BLAKE2b-256 1bd8e2ac02ee9d61eaad0982d803c4d8ac4be52e550a0d49bccebdeb7a4d2f1a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nssurge_api-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ab53bc218e198f3e8b632402e55631108e8cebb6de19373419912507f5b6aef1
MD5 c9f04f89ef416989c6b767b24411cefa
BLAKE2b-256 53ca5f513c8bbe46a65ceec15ab359bc69e0baecca0230e8e65e776ee5a1a5e4

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