Skip to main content

Build Status PyPI version

Simple and opiniated way to build APIs in Python.

FuncServer An abstraction to implement web accessible servers hosting any sort of functionality. This is built on a Tornado core and supports interacting with the server using a web based python terminal making debugging and maintenance easy. In addition the logs emitted by the process can be viewed from within the web interface.

Image

Image

Installation

pip install funcserver

Usage

Basic example

The following is the code to implement the most basic Functionality Server.

from funcserver import Server

if __name__ == '__main__':
    Server().start()

Run it by doing

python example.py run --debug

This server is now started and listening on default port 9345 for commands. You can interact with it using the Web UI by visiting http://localhost:9345/console

If you want to start it on a different port, do

python example.py run --port <port no>

Things to do in the Console

The Web UI console and logs are enabled only when the --debug option is provided.

# see the objects available in the console env
>>> dir()

# write a message to log (open the log tab in a new browser window
# to see the logged message being echoed back). you can use the log
# tab to observe all the logs being written by the application.
>>> server.log.warning('something is happening')

# set a different log level
>>> server.log.setLevel(logging.DEBUG)

# you can import any python module here
>>> import datetime

Calculation server (another example)

You will find an example script in examples/ called calc__server.py.

python examples/calc_server.py

To use the server’s functionality, run the provided example client script in examples/ directory.

python examples/calc_client.py

Debugging using PDB

When it is required to debug the API code using the Python debugger you may have to trigger the API function from the web based python console. However due to the design of FuncServer PDB does not work well in the scenario (as a result of the output being captured by the python interpretation part of FuncServer). To work around this issue a facility has been provided in the form of the “call” utility function available in the python console namespace. The usage is show below.

Let us assume that you have pdb trace set in code as follows:

def some_api_fn(self, a, b):
    import pdb; pdb.set_trace()
    c = a + b
    return c

If you call this api function as follows then debugging will not work and the api call will block from the console.

>>> api.some_api_fn(10, 20)

Instead do this:

>>> call(lambda: api.some_api_fn(10, 20))

Now the pdb console will appear in the terminal where you started your server.

Metadata

Release files for funcserver 0.2.17

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for funcserver 0.2.17
File Size Uploaded
funcserver-0.2.17.tar.gz 245.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for funcserver 0.2.17
File Interpreter ABI Platform
funcserver-0.2.17-py2-none-any.whl Python 2 none any Details

Total release size: 493.7 kB

Release files / funcserver-0.2.17.tar.gz

Download URL funcserver-0.2.17.tar.gz
Size 245.9 kB
Tags Source
SHA-256 checksum
How to use checksums
9777f768defccbd0c1cf9c220a746f43762fd937e63322ace185e45de81ff427
BLAKE2b-256 checksum
How to use checksums
38630350cce39f2104040408a694ac6004cebb2a42ab369238f69caadba7ae7c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / funcserver-0.2.17-py2-none-any.whl

Download URL funcserver-0.2.17-py2-none-any.whl
Size 247.9 kB
Tags Python 2
SHA-256 checksum
How to use checksums
ffee251943ebe56368eb5182106636cd62915abca8d710e85c08051b25a0f92a
BLAKE2b-256 checksum
How to use checksums
9f127d26e277896a40a45160ccaea61d25543d02ad5ffb94bfe891871a65dcf1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.2.17 This release

2 release files

0.2.14

2 release files

0.2.12

2 release files

0.2.10

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page