Package: happypandax-client
happypandax-clientA python client library for communicating withHappyPanda XserversInstallingInstall and update using pip$ pip3 install happypandax-clientExampleGet up and running fast:importhappypandax_clientashpxclientfrompprintimportpprintc=hpxclient.Client("my-client")c.connect(host="localhost",port=7007)c.handshake(user=None,password=None)d=c.send([{"fname":"get_version"}])pprint(d)APIClient (name, host="localhost", port=7007, session_id="", ssl_context=None, timeout=60) â†’ A Client instanceA client for communicating with a HappyPanda X server.Args:name: name of clienthost: HPX server hostport: HPX server hostsession_id: if provided, this will be the session id used in messagesssl_context: seessl.create_default_contexttimeout: seesocket.settimeoutClient.host(property)â†’ strSet or return the HPX server hostClient.port(property)â†’ intSet or return the HPX server portClient.accepted(property)â†’ boolWhether this client has been authenticated or not (this value will only be available after connecting)Client.version(property)â†’ dictThe version message returned from the HPX server (this value will only be available after connecting)Client.guest_allowed(property)â†’ boolWhether guests are allowed on the connected HPX server (this value will only be available after connecting)Client.ready () â†’ boolWhether this client is ready to exchange messages with the HPX serverClient.alive () â†’ boolWhether the connection is still aliveClient.connect (self, host=None, port=None) â†’ boolConnect to HPX serverArgs:host: HPX server host, if set toNonethe provided host on instantiation will be usedport: HPX server port, if set toNonethe provided port on instantiation will be usedClient.handshake (self, user=None, password=None, ignore_err=False, _data={}) â†’ boolPerfom a handshake with the HPX serverArgs:user: usernamepassword: passwordignore_err: don't raise any errorsClient.request_handshake (self, user=False, password=False, ignore_err=False) â†’ boolBasically a re-loginArgs:user: username, if set toFalsethe previously provided username will be usedpassword: password, if set toFalsethe previously provided password will be usedignore_err: don't raise any errorsClient.send_bytes (self, data, raise_on_auth=True) â†’ bytesSend bytedata to server. Receive bytedata from server.Args:data: bytes data to send to serverraise_on_auth: raise an error if client is not authenticatedClient.send_raw (self, data, raise_on_auth=True, encoding='utf-8') â†’ dictSend 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 thefinalizefunction.Args:data: data to send to server, this is a dictraise_on_auth: raise an error if client is not authenticatedencoding: bytes encoding, there shouldn't be a reason to change thisClient.send (self, data, raise_on_auth=True, encoding='utf-8') â†’ dictLikeClient.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 dictsraise_on_auth: raise an error if client is not authenticatedencoding: bytes encoding, there shouldn't be a reason to change thisClient.close () â†’ NoneClose connection with server. Note that it won't be possible to connect again after the connection has been closed.finalize (name, data, session_id="") â†’ dictA 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 clientdata: data to send to server, this is usually a list of dictssession_id: session idThese are all the exceptions that can be raised by the client:ClientError(Exception)Base client exception, all client exceptions will derive from thisConnectionError(ClientError, ConnectionError)Server connection errorServerDisconnectError(ConnectionError, ConnectionAbortedError)Server disconnectedAuthError(ClientError)Auth Base ErrorAuthRequiredError(AuthError)AuthWrongCredentialsError(AuthError)AuthMissingCredentials(AuthError)JSONParseError(ClientError)ExtraUsing a different json libraryIt must support being used as a drop-in replacement for the standardjsonmoduleimport happypandax_client as hpxclient
import ujson
hpxclient.client.json = ujson