Skip to main content

GoodCam Device Proxy lib

Project description

GoodCam Device Proxy

Documentation Status

This library simplifies creating HTTP proxies that can be used to communicate with GoodCam devices in various networks. GoodCam devices contain a built-in client that can be configured to connect automatically to a given proxy. Once connected, the devices will wait for incoming HTTP requests. The proxy simply forwards incoming HTTP requests to the connected devices.

Installation

This library is just a wrapper over the Rust version of the same library. You can install this library using pip:

pip install gcdevproxy

If there is no binary wheel available, pip will try to build also the underlying Rust library. You will need the Rust compiler installed on your system to do this. You can install it easily using:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

See https://www.rust-lang.org/tools/install for more information.

Even though the Rust version of this library can be built for any platform supported by Rust, this Python wrapper is currently available only for Linux systems.

The Rust version of this library also requires OpenSSL (version 1.0.1 or newer) or LibreSSL (version 2.5 or newer). Ubuntu/Debian users can install OpenSSL development files using:

sudo apt-get install libssl-dev

Fedora users can install them using:

sudo dnf install openssl-devel

Usage example

The library supports both blocking and asynchronous API, though the asynchronous API should be preferred due to a better performance. To use the asynchronous API, simply use the create_proxy and RequestHandler equivalents from the gcdevproxy.aio module.

Please keep in mind that when using the blocking API, your request handler MUST be thread-safe! The proxy runtime may call your handler from multiple threads at the same time. You don't have to worry about this when using the asynchronous API because your handler will be called only from the thread running the Python's asyncio event loop (usually the main thread).

Asynchronous API

from gcdevproxy.aio import RequestHandler

...

class MyRequestHandler(RequestHandler):
    async def handle_device_request(self, authorization: Authorization) -> 'DeviceHandlerResult':
        ...

    async def handle_client_request(self, request: Request) -> 'ClientHandlerResult':
        ...

async def main():
    config = ProxyConfig()
    config.http_bindings = [('0.0.0.0', 8080)]
    config.request_handler = MyRequestHandler()

    proxy = await gcdevproxy.aio.create_proxy(config)

    await proxy.run()

if __name__ == '__main__':
    asyncio.run(main())

Blocking API

from gcdevproxy import RequestHandler

...

class MyRequestHandler(RequestHandler):
    def handle_device_request(self, authorization: Authorization) -> 'DeviceHandlerResult':
        ...

    def handle_client_request(self, request: Request) -> 'ClientHandlerResult':
        ...

def main():
    config = ProxyConfig()
    config.http_bindings = [('0.0.0.0', 8080)]
    config.request_handler = MyRequestHandler()

    proxy = gcdevproxy.create_proxy(config)

    proxy.run()

if __name__ == '__main__':
    main()

More examples

See the examples directory in the root of this repository for ready-to-use examples.

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

gcdevproxy-0.1.10.tar.gz (64.3 kB view hashes)

Uploaded Source

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