A simple protocol based on json representation of python dictionaries
Project description
Python Dictionary Transfer Protocol
pydtp is a package defining a protocol for transparently
accessing a remote server with function calls passing
lightweight arguments.
pydtp defines three classes:
- a
Serverclass based onsocketserver.TCPServer - an abstract
Handlerclass to implement to define the Server-responses - an abstract
Clientclass to implement to define the Client interface
The functions implemented on the Client class are redirected to the server class encoding the arguments and the return value in the most transparent way.
Dependencies
The package is developed for Python3.
The package requires numpy plus the standard python libraries
for both the client and server sides.
Example
Define the client implementing two functions,
that just redirect the functions to the query:
import pydtp
class SimpleClient (pydtp.Client) :
def add_one ( self, num ):
return self.query ( 'add_one', [num] )
def capitalize ( self, *strings):
return self.query ( 'capitalize', [strings] )
The query function hides the complexity and allow to
call functions implemented in a Handler:
import pydtp
class SimpleHandler (pydtp.Handler):
def add_one ( self, num ):
return num + 1
def capitalize ( self, strings ):
return {k: k.capitalize() for k in strings}
The server is then instantiated and started on localhost and on a port.
server = pydtp.Server ( ('localhost', 12345), SimpleHandler )
server.start()
The client class is instantiated indicating the address and the port
client = SimpleClient ( ('localhost', 12345) )
client.add_one ( 3 ) ## == 4
client.capitalize ( 'test' ) ## == "Test"
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydtp-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pydtp-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75a5b0a3dd1c52bca27040ceed8e279294194ef0ef13a2bb0064f071818b344b
|
|
| MD5 |
80385d1a5a7a5df47c2a89500cd77101
|
|
| BLAKE2b-256 |
3fa5e94d7ac0239266e8c04ef8fb2e55dda3212089e2257e5cc802e62669f3d3
|