Skip to main content

Use the package from Python

Call the same validators, formatters, helpers, and API client from a Python (Flask) service, and get the same answers as in JavaScript.

Before you begin​

Install enmovil_common_utils. For details, see Get started with Common Utilities.

Call the functions​

Python uses the same function names. Pass options as keyword arguments in snake_case, so minLength becomes min_length:

from enmovil_common_utils import validators, formatters, helpers, request

validators("56001", "pincode", required=True, label="Delivery PIN")
validators("-18.5", "number", min_value=-40, max_value=30) # {'valid': True}
validators("2026-10-07", "date", min_date="today", max_date={"add_days": 30})
formatters("12.34567", "decimal", decimal_places=2) # '12.34'
helpers(rows, "toOptions", label="name", value="id", keep_row=True)
request(BASE_URL + "/api/v1/rfq/bid", "POST", body={"rfq_id": 7}, token=token)

Python rejects camelCase keywords. The reference pages use the JavaScript option names.

What stays the same​

Everything that travels between services is the same in both languages:

  • Rule, formatter, and helper names, such as "pincode" and "decimalUpTo2", because screen configs are shared JSON
  • Results, including error codes such as "minLength" and their messages, so you can compare a browser's errors with a server's

A JSON number such as 100.0 reads as "100", and lengths count the way JavaScript counts them.

Differences from JavaScript​

Python differs from JavaScript in these places:

AreaJavaScriptPython
OptionscamelCase, in an object: { minLength: 6 }snake_case keywords: min_length=6
Date bound{ addDays: n }{"add_days": n}, and {"addDays": n} from a JSON config
financialYear keysstartYear, endYearstart_year, end_year
valueFromEventAvailableNot available
request download"blob" gives a Blob"blob" gives bytes
request filesFile or BlobBytes, an open file, or (filename, bytes[, content_type])
currency, decimalGroupedThe platform's locale dataThe Babel library, so output can differ slightly