Jina Sandbox

Jina Sandbox allows you to try out different Jina Executors online and see how they work together without downloading all the Executors to your local machine.

Prerequisites

  • Knowledge about Jina Executor

  • Knowledge about Jina Hub

Start a Flow using Jina Sandbox

  1. from jina import Flow, Document
  2. f = Flow().add(uses='jinahub+sandbox://MiaoTestExecutor1')
  3. with f:
  4. r = f.post('/', inputs=Document(text='world'), return_results=True)
  5. print(r[0].text)

This will start a Flow that only has one online Executor, and will send a document to it. The document will be processed by the Executor and the result will be returned.

Sandbox Lifecycle

The sandbox will not be removed immediately after the Flow is closed. It will be kept alive until there is no traffic during this certain period. For now, the default period is 15 mins.

Sandbox will be shared with other users. Sometimes you will start the sandbox very quickly because the other users already started it.

It will find the existing sandbox by three factors:

  • Executor name

  • Executor tag

  • Jina version of Gateway

If all these three factors are matched, then it will reuse the existing sandboxes.

Caution

If the Jina version of Gateway is later than the latest released Jina version (things happens when you are in the master branch of jina repository), then the sandbox will always be created instead of reused.

Version Consistency

The Jina version inside the Sandbox will be the same as the one in the place where the Flow was run. For example, if you run the Flow in your local machine, then it’s the version of Jina in your local pip packages.

Mixed with non-sandbox Executors

It can also be mixed with non-sandbox Executors. For example, pure Python class.

  1. from jina import Flow, Document, DocumentArray, Executor, requests
  2. class MyExecutor(Executor):
  3. @requests
  4. def process(self, docs: DocumentArray, **kwargs):
  5. for doc in docs:
  6. doc.text = '(first hello, from MyExecutor)' + doc.text
  7. return docs
  8. f = Flow().add(uses=MyExecutor).add(uses='jinahub+sandbox://MiaoTestExecutor1')
  9. with f:
  10. r = f.post('/', inputs=Document(text='world'), return_results=True)
  11. print(r[0].text)