Skip to main content

Client library for communicating with HappyPanda X servers

Project description

happypandax-client

A python client library for communicating with HappyPanda X servers

Installing

Install and update using pip

$ pip3 install happypandax-client

Example

Get up and running fast:

import happypandax_client as hpxclient
from pprint import pprint

c = hpxclient.Client("my-client")
c.connect(host="localhost", port=7007)

c.handshake(user = None, password = None)
d = c.send([{"fname": "get_version"}])
pprint(d)

API

Client (name, host="localhost", port=7007, session_id="", ssl_context=None, timeout=60) → A Client instance

A client for communicating with a HappyPanda X server.

Args:

Client.host (property) → str

Set or return the HPX server host

Client.port (property) → int

Set or return the HPX server port

Client.accepted (property) → bool

Whether this client has been authenticated or not (this value will only be available after connecting)

Client.version (property) → dict

The version message returned from the HPX server (this value will only be available after connecting)

Client.guest_allowed (property) → bool

Whether guests are allowed on the connected HPX server (this value will only be available after connecting)

Client.ready () → bool

Whether this client is ready to exchange messages with the HPX server

Client.alive () → bool

Whether the connection is still alive

Client.connect (self, host=None, port=None) → bool

Connect to HPX server

Args:

  • host: HPX server host, if set to None the provided host on instantiation will be used
  • port: HPX server port, if set to None the provided port on instantiation will be used

Client.handshake (self, user=None, password=None, ignore_err=False, _data={}) → bool

Perfom a handshake with the HPX server

Args:

  • user: username
  • password: password
  • ignore_err: don't raise any errors

Client.request_handshake (self, user=False, password=False, ignore_err=False) → bool

Basically a re-login

Args:

  • user: username, if set to False the previously provided username will be used
  • password: password, if set to False the previously provided password will be used
  • ignore_err: don't raise any errors

Client.send_bytes (self, data, raise_on_auth=True) → bytes

Send bytedata to server. Receive bytedata from server.

Args:

  • data: bytes data to send to server
  • raise_on_auth: raise an error if client is not authenticated

Client.send_raw (self, data, raise_on_auth=True, encoding='utf-8') → dict

Send json-compatible dict to server. Receive json-compatible from server.

Note that this method will not add anything to your message and expects you to add the name and session yourself. See the finalize function.

Args:

  • data: data to send to server, this is a dict
  • raise_on_auth: raise an error if client is not authenticated
  • encoding: bytes encoding, there shouldn't be a reason to change this

Client.send (self, data, raise_on_auth=True, encoding='utf-8') → dict

Like Client.send_raw, but as a convenience, this method will wrap your message into the required message structure HPX expects and automatically sets the session and name:

final_msg = {
        'session': client.session_id,
        'name': client.name,
        'data': data, # <--- your message is put here
    }

Args:

  • data: data to send to server, this is usually a list of dicts
  • raise_on_auth: raise an error if client is not authenticated
  • encoding: bytes encoding, there shouldn't be a reason to change this

Client.close () → None

Close connection with server. Note that it won't be possible to connect again after the connection has been closed.

finalize (name, data, session_id="") → dict

A helper function that will wrap your message up like this:

msg = {
        'session': session_id,
        'name': name,
        'data': data, # <--- your message is put here
    }

Args:

  • name: name of client
  • data: data to send to server, this is usually a list of dicts
  • session_id: session id

These are all the exceptions that can be raised by the client:

ClientError(Exception)

Base client exception, all client exceptions will derive from this

ConnectionError(ClientError, ConnectionError)

Server connection error

ServerDisconnectError(ConnectionError, ConnectionAbortedError)

Server disconnected

AuthError(ClientError)

Auth Base Error

AuthRequiredError(AuthError)

AuthWrongCredentialsError(AuthError)

AuthMissingCredentials(AuthError)

JSONParseError(ClientError)

Extra

Using a different json library

It must support being used as a drop-in replacement for the standard json module

import happypandax_client as hpxclient
import ujson
hpxclient.client.json = ujson

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

happypandax-client-1.0.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

happypandax_client-1.0.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file happypandax-client-1.0.0.tar.gz.

File metadata

  • Download URL: happypandax-client-1.0.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.5

File hashes

Hashes for happypandax-client-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b1485c4039eb8d07989c43b88fe54af337e8e59b47cbc7a9d87419516ba252d8
MD5 7b9933decd693e9e7f59ed7377f962a2
BLAKE2b-256 71834f4ccdfc4bd12a6febb77e5422cfa8fa4c813ba7f12c0f6dc358a2b3e2c9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: happypandax_client-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.5

File hashes

Hashes for happypandax_client-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 10796ba034a9526dbd29e1a68a5a9cb8426e7977f193e91adbaf00ca0447e936
MD5 ddf63929b7fd420338f30b0b2b387280
BLAKE2b-256 35569c17c7c3bc7b60951c7d728cb7c8abb8b7bd30e43a9b5da4efc0a20bfbd6

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