Skip to main content

Python connector module for Node.JS applications

Project description

Python connector module for Node.JS applications. This packages allows Python functions to be called and process Node.JS JSON request. This packages complements PyConnector module for Node.JS.


Install using pip

pip install nodeconnector

Python version

Python 3.6+ is required.


A simple minimal API interface can be created using the following example. Note that handle/resolver functions are executed in a separate thread. Context information can be using nodeconnector.Interface.handle( 'query_type', resolve_function, [ ctx ] ).

This object will be passed to all resolve_function calls and can be used to store information between queries.

import sys
import time
import argparse
import nodeconnector

# argument parsing, PyConnector automatically sends this
parser = argparse.ArgumentParser( description = 'Python Exposed API' )
parser.add_argument( '--pynodeport', help = 'PyConnector Node.JS query port', default = 24001 )
args = parser.parse_args()

# python version query
def nodeq_version( args, ctx = {} ):
    return ( '%d.%d.%d' % ( sys.version_info[ 0 ], sys.version_info[ 1 ], sys.version_info[ 2 ] ) )

# increment value query
def nodeq_increment( args, ctx = {} ):
    # return value
    ctx[ 'inc' ] += 1
    args[ 'value' ] = ctx[ 'inc' ]

    return args

# create interface
nodeq = nodeconnector.Interface( )

# queries are executed on a separate thread, a context object can be used to pass data
nodeq.handle( 'pyversion', nodeq_version )
nodeq.handle( 'increment', nodeq_increment, dict( inc = 0 ) )

# launch API
nodeq.listen( port = args.pynodeport )

# wait
while( True ):
    time.sleep( 0.001 )

License (MIT)

Copyright (C) 2019 Cristian Dobre .

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

nodeconnector-1.0.5.tar.gz (3.8 kB view hashes)

Uploaded source

Built Distribution

nodeconnector-1.0.5-py3-none-any.whl (3.0 kB view hashes)

Uploaded py3

Supported by

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