An Executor is a self-contained service that performs a task on Documents.

You can create an Executor by extending the Executor class and adding logic to endpoint methods.

Why use Executors?#

Once you’ve learned about Documents and DocList from docarray, you can use all its power and expressiveness to build a multimodal application. But what if you want to go bigger? Organize your code into modules, serve and scale them? That’s where Executors come in.

  • Executors let you organize functions into logical entities that can share configuration state, following OOP.

  • Executors can be easily containerized and shared with your colleagues using jina hub push/pull.

  • Executors can be exposed as a service over gRPC or HTTP using ~jina.Deployment.

  • Executors can be chained together to form a ~jina.Flow.

Minimum working example#

from jina import Executor, requests, Deployment
from docarray import DocList
from docarray.documents import TextDoc

class MyExecutor(Executor):
    def foo(self, docs: DocList[TextDoc], **kwargs) -> DocList[TextDoc]:
        for d in docs:
            d.text = 'hello world'
        return docs

with Deployment(uses=MyExecutor) as dep:
    response_docs = dep.post(on='/', inputs=DocList[TextDoc]([TextDoc(text='hello')]), return_type=DocList[TextDoc])
    print(f'Text: {response_docs[0].text}')
─────────────────────── 🎉 Deployment is ready to serve! ───────────────────────
╭────────────── 🔗 Endpoint ───────────────╮
│  ⛓     Protocol                    GRPC │
│  🏠       Local   │
│  🔒     Private  │
│  🌍      Public  │
Text: hello world