Skip to main content

Turn any Python function into a service that receives JSON payloads on some port.

Project description

Service-it

Version status License Python version compatibility Version on GitHub Version on PyPi
Build (Actions) Coverage (coveralls) Maintainability (Code Climate) Scrutinizer Code Quality Created with Tyrannosaurus

Turn any Python function into a service that receives JSON payloads on some port.

Here’s a trivial example:

import serviceit
def receiver(payload):
    print(payload)
server = serviceit.server(1533, receiver)
# Now it will receive JSON on 1533. For convenience:
server.client().send(dict(message="hi"))
print(server.bytes_processed)

More complex example: isolate code

You can use this to isolate a component of you code. For example, rdkit can be installed through Conda but not Pip (or Poetry). So, create a service and import it in an Anaconda environment to create a server, and in your pip-installed client code.

In a Conda environment, create a service that listens on port 1533:

import serviceit

def _receiver(payload):
    # noinspection PyUnresolvedReferences
    from rdkit.Chem.inchi import InchiToInchiKey
    inchikey = InchiToInchiKey(payload["inchi"])
    print(inchikey)

server = serviceit.server(1533, _receiver)

On your pip-install client side:

import serviceit
client = serviceit.client(1533)
client.send(dict(inchi="InChI=1S/H2O/h1H2"))

New issues and pull requests are welcome. Please refer to the contributing guide.
Generated with Tyrannosaurus.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for serviceit, version 0.2.0
Filename, size File type Python version Upload date Hashes
Filename, size serviceit-0.2.0-py3-none-any.whl (10.7 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size serviceit-0.2.0.tar.gz (11.0 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page