Create a New Project

Let’s write a small application with our new Jina development environment. To start, we’ll use Jina CLI to make a new project for us. In your terminal of choice run:

jina new hello-jina

This will generate a new directory called hello-jina with the following files:

|- executor1/
        |- config.yml
  • is the entrypoint of your Jina project. You can run it via python

  • executor1/ is where we’ll write our Executor code.

  • config.yml is the config file for the Executor. It’s where you keep metadata for your Executor, as well as dependencies.

There may be some other files like, manifest.yml requirements.txt to provide extra metadata about that Executor. More information can be found here.

cd hello-jina

You should see this in your terminal:

           [email protected][I]:🎉 Flow is ready to use!
	🔗 Protocol: 		GRPC
	🏠 Local access:
	🔒 Private network:
	🌐 Public address:
['hello, world!', 'goodbye, world!']

Adding dependencies

You can use any third-party Python library in Executor. Let’s create executor1/requirements.txt and add pytorch to it.

Then in, let’s add another endpoint /get-tensor as follows:

import numpy as np
import torch

from jina import Executor, DocumentArray, requests

class MyExecutor(Executor):
    def bar(self, docs: DocumentArray, **kwargs):
        for doc in docs:
            doc.tensor = torch.tensor(np.random.random([10, 2]))

A small Jina application

Now let’s write a small application with our new dependency. In our, add the following code:

from jina import Flow, Document

f = Flow().add(uses='executor1/config.yml')

with f:
    da ='/get-tensor', [Document(), Document()])

Once we save that, we can run our application by typing:


Assuming everything went well, you should see your application print this to the screen:

       [email protected][I]:🎉 Flow is ready to use!
	🔗 Protocol: 		GRPC
	🏠 Local access:
	🔒 Private network:
	🌐 Public address:
tensor([[[0.9594, 0.9373],
         [0.4729, 0.2012],
         [0.7907, 0.3546],
         [0.6961, 0.7463],
         [0.3487, 0.7837],
         [0.7825, 0.0556],
         [0.3296, 0.2153],
         [0.2207, 0.0220],
         [0.9547, 0.9519],
         [0.6703, 0.4601]],

        [[0.9684, 0.6781],
         [0.7906, 0.8454],
         [0.2136, 0.9147],
         [0.3999, 0.7443],
         [0.2564, 0.0629],
         [0.4713, 0.1018],
         [0.3626, 0.0963],
         [0.7562, 0.2183],
         [0.9239, 0.3294],
         [0.2457, 0.9189]]], dtype=torch.float64