Skip to main content

Incorporate non-functional requirements in function definitions

Project description


Specify non-functional requirements in your Python code.


pip install python-liang


Specify the amount of time a function is required to run under.


Used to specify when a function is _required_ to run within `threshold_seconds`.
The function is guaranteed to terminate within `threshold_seconds`. Either:
- The function runs successfully to completion, or
- TimeoutError is raised when the function takes too long

Used to specify when a function _should_ run within `threshold_seconds`.
The function is allowed to run to completion.
If the function takes longer than `threshold_seconds`, a warning will be logged.

@liang.latency.require(threshold_seconds=3, handler=CustomHandler)
@liang.latency.recommend(threshold_seconds=3, handler=CustomHandler)
Can specify CustomHandler to handle when a function exceeds `threshold_seconds`.
CustomHandler needs to inherit from liang.handlers.FailureHandler and implement the
`.handle(self, context: environment.ExecutionContext)` method.


For example, we may want to enforce that sorting an array of ten integers takes no more than 3 seconds:

import liang.latency

def timsort_array(array):

array = list(reversed(range(10)))
# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

The function should complete as normal. But if we try a less efficient approach:

import random

def bogosort_array(array):
    while not all(array[i] <= array[i+1] for i in range(len(array)-1)):

array = list(reversed(range(10)))
# TimeoutError: Function 'bogosort_array' expected to have LATENCY_SECONDS to be 3

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

python-liang-0.0.2.tar.gz (4.1 kB view hashes)

Uploaded source

Built Distribution

python_liang-0.0.2-py3-none-any.whl (5.2 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page