Skip to main content

Wrapper to convert arbitrary code into a uvicorn/fastapi implementation for Unstructured Platform

Project description

Unstructured Platform Plugins

CI

Information about how to build custom plugins to integrate with Unstructured Platform.

Plugin Development

Any plugin must be published in a dedicated docker image with all required dependencies that when run, exposes an api on port 8000 with the required endpoints to interact with the Unstructured Platform product:

  • /invoke: A POST endpoint which gets all data to run the underlying logic in the request body and expects a json serializable response.
  • /schema: A GET endpoint which publishes a json schema formatted response with the schema of the input and output expected by the plugin.
  • /id: A GET endpoint which publishes a string unique identifier for this instance of the plugin. Will default to a hash of the schema response if one is not set explicitly.

Utility CLI

When installing this repo, it also installs the cli etl-uvicorn. This takes a pointer to any generic python function and wraps it in a FastApi application to conform to the patterns that are expected by the api hosting the plugin logic. This cli extends the existing uvicorn cli which takes in a pointer to a fastapi instance or factory but instead takes in a pointer to a python function/class which gets wrapped with a FastApi application.

Example usage

For all following commands, make sure you have the local repo in your PYTHONPATH:

export PYTHONPATH=.

Wrapping a basic function with a typed dict response

etl-uvicorn test.assets.typed_dict_response:sample_function

Wrapping a basic async function with a typed dict response

etl-uvicorn test.assets.async_typed_dict_response:async_sample_function

Wrapping a class. For this to work, the class must be self instantiating. When passing a class in, a method needs to be passed in as well, otherwise __call__ is used. The following example returns a pydantic BaseModel

etl-uvicorn test.assets.pydantic_response_class_method:SampleClass --method-name sample_method

Wrapping an instance of a class.

etl-uvicorn test.assets.pydantic_response_class_method:sample_class --method-name sample_method

The CLI does some validation on the wrapped function, which must have explicit inputs and outputs, meaning *args and **kwargs are not supported. These will cause the cli to fail fast.

etl-uvicorn test.assets.improper_function:sample_improper_function

/id requirements

All the the above examples caused the CLI to autogenerate the /id endpoint with a hash of the generated schema. However, you can also provide it a reference to use for the id value. This can be a reference to a concrete value (i.e. plugin_id="my_plugin_id") or a function in the same way that one was passed in to be wrapped above.

Will populate the response of /id with the static value of hash_value:

etl-uvicorn test.assets.typed_dict_response:sample_function --plugin-id test.assets.simple_hash_value:hash_value

Can populate it using a lambda:

etl-uvicorn test.assets.typed_dict_response:sample_function --plugin-id test.assets.simple_hash_lambda:hash_lambda_fn

Similar to the function being wrapped, can also use a class:

etl-uvicorn test.assets.typed_dict_response:sample_function --plugin-id test.assets.simple_hash_class:GetHash --plugin-id-method my_hash

Or the instantiated class:

etl-uvicorn test.assets.typed_dict_response:sample_function --plugin-id test.assets.simple_hash_class:get_hash_class_instance --plugin-id-method my_hash

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

unstructured_platform_plugins-0.0.29.tar.gz (20.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file unstructured_platform_plugins-0.0.29.tar.gz.

File metadata

File hashes

Hashes for unstructured_platform_plugins-0.0.29.tar.gz
Algorithm Hash digest
SHA256 6c1e5b2ac4e5e3f9630609380d6110d21563b1644da86f96fd3a8c87ca8c5de8
MD5 7a21ec01b31c1d2399aa48175034734e
BLAKE2b-256 b63b699a9e944039693a25951a09b19598e9442fc85479efdadbbf9b1a2a5860

See more details on using hashes here.

File details

Details for the file unstructured_platform_plugins-0.0.29-py3-none-any.whl.

File metadata

File hashes

Hashes for unstructured_platform_plugins-0.0.29-py3-none-any.whl
Algorithm Hash digest
SHA256 01ac17a77f516c7ad96a0153fa0ff8e8b3421538ea177e9200d13a430e2903bd
MD5 084192573b13ad00ad4bd0d07b91e313
BLAKE2b-256 a76c5838fd74680996283f6a2340b61e9f744fc0ef1100b7ee62d056fed04f86

See more details on using hashes here.

Supported by

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