No project description provided
Project description
Feathr Online Transformation Python Support
This is the Python wrapper of the Feathr online transformation service.
There are 2 major classes in this package:
-
PiperService
, this is the service class, it is used to start a HTTP service to handle the transformation requests. It doesn't support HTTPS and authentication, so you may need to setup gateway or proxy to handle the security issues. ThePiperService
class has astart
method to start the HTTP service in blocking mode, andstart_async
method to start the service in theasync
context. -
Piper
, this is the transformation engine, it can be use to transform data directly, mainly for development and testing purpose. ThePiper
class has aprocess
method to transform data in blocking mode, andprocess_async
method to transform data in theasync
context.
Both above classes support UDF and UDLF written in Python.
NOTE: Because of the GIL, pure Python code cannot run concurrently, that means using Python UDF could slow down the transformation service, especially on heavy load.
Value Types
All values passed to the pipeline must be in one of the following types:
None
- Simple types:
bool
,int
,float
,str
- Date/time is represented as
datetime.DateTime
. - List: List of supported types.
- Map: Map of supported types, keys must be string, and value can be any supported type.
All values returned by the pipeline will also be in above types.
NOTE: When using Python big integer, exception will be thrown if any it exceeds the range of 64-bit signed integer.
User Defined Function (UDF) in Python
The UDF is implemented as ordinary Python function, and it must be registered to the service before it can be used in the pipeline.
- The UDF function can only accept positional arguments, keyword arguments are not supported.
- The UDF function must be able to be invoked by the usage in the DSL script, i.e. a UDF with 2 fixed arguments and 1 optional argument can be invoked as
udf(1, 2)
orudf(1, 2, 3)
, but notudf(1, 2, 3, 4)
orudf(1)
. - The UDF function may raise any exception, and the returned value will be record as an error. This error will be propagated to the caller.
- Every function and operator that takes error as the input will return the error.
- At the final output stage of the pipeline, the error value will be converted to
None
, and the error will be recorded in a separated error list. - The UDF function will never see the error as the input, the invocation is bypassed before the UDF function is called if any of the argument is error.
- The execution order is non-deterministic, so the UDF function shall not make any assumptions.
- The UDF function should not block, such behavior is not strictly forbidden but the performance will be impacted significantly.
User Defined Lookup Function (UDLF) in Python
Usually lookup
is to fetch external data, such as a database or a web service, so the lookup data source is implemented as a Python async functions, and it must be registered to the piper or the service before it can be used in the pipeline.
The lookup function is called with a single key and a list of requested field names, and it should return a list of rows that each row is a list that aligns with the requested fields, or an empty list when lookup failed. The key must be in the supported simple types, list and dict cannot be used as key, and using None
as the key will get None
as the value of all returned fields without actually calling the lookup function.
async def my_fancy_lookup_function(key: Any, fields: List[str]) -> List[List[Any]]:
...
return [
[some_data[f] for f in fields],
[some_other_data[f] for f in fields],
]
The lookup function must be added to the Piper
or PiperService
before it can be used in the pipeline:
piper = Piper(pipeline_def, {"lookup_name": my_fancy_lookup_function}, ...)
or
svc = PiperService(pipeline_def, {"lookup_name": my_fancy_lookup_function}, ...)
Then you can use the lookup data source in the pipeline in a lookup
transformation:
pipeline_name(...)
| ...
| lookup field1, field2 from lookup_name on key
| ...
;
or a join
transformation:
pipeline_name(...)
| ...
| join kind=left-inner field1, field2 from lookup_name on key
| ...
;
Once the user-defined lookup function is used, the Piper
and PiperService
must be used in async
context, otherwise all async function will never be executed and the program may hang forever.
Also you need to replace process
with process_async
, and start
with start_async
.
piper = Piper(pipeline_def, {"lookup_name": lookup_function})
async def test():
await piper.process_async(...)
asyncio.run(test())
For more information about Python async programming, please refer to Python Asyncio.
NOTE:
- Because of the asynchronous nature of the lookup function, it's recommended to use
asyncio
compatible libraries to implement the lookup function, traditional blocking libraries may cause the performance issue, e.g. useaiohttp
orHTTPX
instead ofRequests
. - This package only supports
asyncio
,Twisted
orGevent
based libraries are not supported. - In order to lookup data from a standard JSON-based HTTP API, you can use builtin HTTP client instead of implementing your own lookup function, register the lookup data source either in a JSON string or a
dict
with correct content, detailed doc is at here. - The
feathrpiper
also has builtin support of SqlServer/AzureSQL, Sqlite3, and Azure CosmosDb.
Integration with Other Web-Service Frameworks
The feathrpiper
contains built-in web service, but it doesn't support HTTPS and authentication, and has a specific HTTP API spec which cannot be changed from the Python side. In case you need to use it in any other scenario, you may integrate it with other Web service frameworks.
- Flask: prefer to use async version of Flask, such as Flask-Async, Flask-RESTful-Async, Flask-RESTX-Async, etc. And you should use
process_async
to process the request. - FastAPI: FastAPI is fully async-based, use
process_async
to process the request. - Any other Web framework that doesn't support async: You can use
process
in non-async context, but the user-defined lookup function feature will be unavailable.
A demo of integrating with FastAPI is at here
Packaging and Deployment
The feathrpiper
package is a standard Python package without external dependency, you need to write your own code using the package to implement your own transformation service.
The packaging and the deployment process is also standard, refer to the official document if you need to build Docker image, currently we don't have any pre-built Docker image for the Python package.
In most cases, the packaging process could be like:
- Prepare the
requirements.txt
file which includes thefeathrpiper
package and all the other dependencies.# This package feathrpiper >= 0.4.3 # Any other dependencies pandas == 1.5.2 pytorch >= 1.0.0 ...
- Prepare a
Dockerfile
file which includes therequirements.txt
file and the code to run the service.FROM python:3.9-slim-buster COPY requirements.txt /tmp/ RUN pip install -r /tmp/requirements.txt COPY . /app WORKDIR /app # In case you want to use the built-in web service provided by `PiperService` class and it's listening at the port 8000 # Or you write your own web service and it's listening at the port 8000 EXPOSE 8000 CMD ["python", "main.py"]
- Build the Docker image:
docker build -t my_image .
- Run the Docker image:
docker run -p 8000:8000 my_image
Building from Source
The feathrpiper
package is written in Rust, so you need to setup the Rust toolchain to build it from source. The Rust toolchain can be installed from here. The development is done in Rust 1.65, older version may not work.
- Install
maturin
:pip install maturin
- Build the package under the
feathrpiper_root/python
directory:maturin build --release
More information about maturin
can be found here. Please note that running cargo build
in the top level directory won't build the Python package because the python package project is excluded from the workspace for some technical issues.
Limitations and Known Issues
- The
PiperService
class supports plain HTTP only, and it doesn't support any kind of authentication. - The
feathrpiper
supports Python 3.7~3.11, no support for Python 3.6 or earlier, and no support for Python 2. - The package published on PyPI only support following platforms:
- Linux arm64
- Linux armv7
- Linux x86_64
- macOS x86_64/AppleSilicon universal
- Windows x86_64
You need to build the package from source if you need to use it on other platforms.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for feathrpiper-0.4.8-cp311-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 883fe39b4cda3d33b79e4635c854a0aad483881eff21f1d3cd6e278704aa27b8 |
|
MD5 | 3097038402e5041e82df780d388c2d79 |
|
BLAKE2b-256 | b6e1140e43d45a4edbec7d3fb929e230b66f6e74e79a53cfc4eb39ea0a48188c |
Hashes for feathrpiper-0.4.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33b97a380ba32480d40c8d042726fdc0ac75000e330e5a5288ab21586bfe2287 |
|
MD5 | 2317a6454ed509e5f10ece2c9e44ae13 |
|
BLAKE2b-256 | f5a5fd0d68960da8faa4c788c2a3b7b58c171f250b0e738109b8a6aa40c5c9ee |
Hashes for feathrpiper-0.4.8-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a06ddf357da35fefc92fd9c91eae3ebe9a726f9c1223ff33b18c75e0ea51965d |
|
MD5 | f0b9fcdf5f0463a59435dded31f683be |
|
BLAKE2b-256 | 21b3da62c06d95531bb6890790ea745d14834bc701dd9e33cb7fb099681451e1 |
Hashes for feathrpiper-0.4.8-cp311-cp311-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6fe07fcbd4e3399c37021c92dd78953c2928bab0b672ad6db8b1ffabcc5ed914 |
|
MD5 | 88f8456e135750c97431b0705ecfb0e4 |
|
BLAKE2b-256 | 45e2fb6267fa7ad393be307aed329f02e0082e2175b751d57f608191821ea84f |
Hashes for feathrpiper-0.4.8-cp311-cp311-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c643a9d1756af22590a6fe819496c78a0d2422ccee853946569402a3681db65f |
|
MD5 | 6fb4bb1a9f04875ba100cc34df042db9 |
|
BLAKE2b-256 | 762cc6c8ca8db957ea496316a7a3c9768ee3fae8b24fda6d4589b7d5d15b6558 |
Hashes for feathrpiper-0.4.8-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3787c7564f4a751e6b8bc0808422ee62d00f4190a4d42704b3156d66aa0b206e |
|
MD5 | a86ec9207b41de960e4da3e52754adf2 |
|
BLAKE2b-256 | 88e67d40d51a4973e7922a726afe2035bc3fd4884174a2abe7ba0189fd3f9e8d |
Hashes for feathrpiper-0.4.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d012f7a8873790381cbc375880d16141db1e3a283f5deaac64a390272e8784e |
|
MD5 | 6c4ab32186ceffc10448d6ff74166c79 |
|
BLAKE2b-256 | 1e6b3e19221b943b611348756376afcf8125d26582e2a5ab366dfd43dfd8cd08 |
Hashes for feathrpiper-0.4.8-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73839a32206cf2d73c4130d429fcc7ffd1e8194c9d5e0f715dc483d7ec4bb2c1 |
|
MD5 | 979f2fc00404f7b03e95d1ac7f8f8bd3 |
|
BLAKE2b-256 | 3982e7076a21ac8fa64e46c937d33cd0ac248061fe96e11545ba661eaa3500a8 |
Hashes for feathrpiper-0.4.8-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 385ee19cd980ef9d3b2d4353be71b82692523ec4e3858ca8454dcc848d10b5b0 |
|
MD5 | da63854dbac75d3c6273c7377fd1416f |
|
BLAKE2b-256 | ff4a45baa3267c49b7b82fa0fbd0dd45886b97ca665fcba5f782839d10d0706b |
Hashes for feathrpiper-0.4.8-cp310-cp310-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa23027079a7e5e2ececcb6ce8ee5c488a20d68d7a7159948bba96825e380ed7 |
|
MD5 | d9f121f5e4c4825c9d31430a29642161 |
|
BLAKE2b-256 | 4f9e0eafe942bc1af5f1e1e6605dfc49d9cd793b428cbc273aabaa4bc60e4ff0 |
Hashes for feathrpiper-0.4.8-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e44c9ca8ce4bab66a222cca894d840f715925cde2a6edfc3dfb032e551baf08 |
|
MD5 | 4728a8d79628ed1e809e52e2f48f01f4 |
|
BLAKE2b-256 | 2ad4968fd6d83af5e86410d89bb69666c34d076a589c23b9958a7d38c2989a4c |
Hashes for feathrpiper-0.4.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fda6c2cbbd22420d4652b12676e6c3c936e1c1015dac1756eb79550945e7766e |
|
MD5 | 07156c258e5b449c862b6440cc841682 |
|
BLAKE2b-256 | 1bc4d0c0844ac54c19c51e433ae0ac908c525b57a0426dd2bcbb24f5ae60a812 |
Hashes for feathrpiper-0.4.8-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b74afac61de0db5cbf2e216cbadf08cdff1ee1e6af4cea7baba957e6aa020d4 |
|
MD5 | de50a937b3cb2db75d6e37180ae1368d |
|
BLAKE2b-256 | f0a444387592df4517f9af939c3ea6e57e10926d03806744a555e15a1463b572 |
Hashes for feathrpiper-0.4.8-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20fd1613e1fb9f97ed1afd5298364dac306a5bdac7b47a54eababc3d69e657d7 |
|
MD5 | a16eb29a9accc315a4dd905191878d6a |
|
BLAKE2b-256 | a778749a59cd3837b491e575c13ea307feeec98ee1c9f5a4335b08557ed700b7 |
Hashes for feathrpiper-0.4.8-cp39-cp39-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a70a40d22a8aa02aeb797ac05806a6495475a729a7802d6050435347f354816 |
|
MD5 | 76b18013287ec6bc0ac24ba01d7d66b5 |
|
BLAKE2b-256 | 075d54aac4d8759386211b24b2b3d195df5d24ccb5f8ef8fcec402cadd4ca7ed |
Hashes for feathrpiper-0.4.8-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a3e5a33599b008e9e864873d5af63c5e0d881a3e1fff4500e208c1fde574227 |
|
MD5 | 4f6af4b19800af86fdf0f125ad22ed4a |
|
BLAKE2b-256 | e5f3a148633be182f691ca31f6f4d2aa3c45b31a6eaa1fa44f69c45fa21c82a4 |
Hashes for feathrpiper-0.4.8-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c97360bff4983821a6881d90c0f76ce7e5e5c4a3caab90fc6abff1db5491fcde |
|
MD5 | ca25805bda7f44e5bb1412907804e99b |
|
BLAKE2b-256 | 72f6b50720c252e4fe1a572c481520e220f40b1dcbfe96938abb1322f5c2f8ec |
Hashes for feathrpiper-0.4.8-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90abe7dd165d48e78ff43109c29887fa8d79559d7ba8007d49cc040d0657c97c |
|
MD5 | 1d41ab86919d6d6892b7edc0c3e08e51 |
|
BLAKE2b-256 | 55cfdc68a57b3300e66394e24ea9ae81540e754a7024d82c1e407c99919f6f3a |
Hashes for feathrpiper-0.4.8-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a40bb73d182bfb0acdcd8db4865537b357d87da70827c7e8cae13b51a896acc4 |
|
MD5 | ef87f8b5139f07b5952f65a0c7994bab |
|
BLAKE2b-256 | d94de3c00b269b5aec380a5472e376997056d12ac965fd35a64351b3d707b967 |
Hashes for feathrpiper-0.4.8-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aaca768d90babda63d4de033b768f832c14a7e137b7da2c84c6542fb02bfcfab |
|
MD5 | f1f7073eb0d4f06209eed8225735206b |
|
BLAKE2b-256 | ef24c177f1f96b285f715a806130a435de37a2e2cbf4edc862e6e46231e86d3e |
Hashes for feathrpiper-0.4.8-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 603983eead2c8f4ad8170e81d9108fd04a08a29361fe7409f7cd54a2daa3d6a6 |
|
MD5 | 289161b79806447ae37d491c5ea851a8 |
|
BLAKE2b-256 | c06137998ac0d4904ef4372cfdb9481063771cf734a68bc4acb7151a743d46c0 |
Hashes for feathrpiper-0.4.8-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ecc24e8f47de7b12cbc761e31bb520bc67fb89dae6763cdc5039c621fccd9be |
|
MD5 | 9781790d15000d677801b7c242954a5a |
|
BLAKE2b-256 | 37773134ac1895f30ab5de6eee23a72e117fd98644e3609d39a250f100b4e643 |
Hashes for feathrpiper-0.4.8-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8abb0a4b98dea9ae824507e972b7001c33916db8eed45b64abe0bdab7718272 |
|
MD5 | 2141ce97afc36dfcc842d8dfcf94c602 |
|
BLAKE2b-256 | 72489a7a94d104ec3a5a93e618e1e4f37787292b9d7254707a81d96bbd3af432 |
Hashes for feathrpiper-0.4.8-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 751fc8337f22ae8b30802b520b14899e32aee4874422dbe374816b4bf6c81ec1 |
|
MD5 | afebc779dfae8008561b25818a46a3ab |
|
BLAKE2b-256 | 1b1f92158922e33cfe18f1db410e1e8d48f8914313533e7b34bf50e58744b5e7 |
Hashes for feathrpiper-0.4.8-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e2973c2ae0d686662ebfe2aec2cfce181c29dbca73f7ef39eeabe207734ec12 |
|
MD5 | a746f24eb7b88b6a0f7170700407324c |
|
BLAKE2b-256 | 67a4bd6987e6d9b5a47cee1270bfed864581f3bb22423536eb58f4517fec935a |