Getting Started!
The easiest way to install the library is to use poetry or pip:
pip install "arkitekt[all]"
This will install the library with all its dependencies, including the Arkitekt CLI as well as all supporting libraries for each service.
This is the recommend way to install arkitekt, especially if you are not planning to use arkitekt as a dependency in another project.
If you are planning to only use arkitekt as a dependency in another project, you can install it without the CLI and add it additional dependencies as needed.
pip install arkitekt
# pip install mikro (for microscopy support)
# pip install rekuest (for registering nodes)
Choose your style
The best way to explore what Arkitekt can do is to follow one of the tutorials. Here you can find a list of tutorials that will guide you through the process of creating your first app. But first let's discuss the two different styles of developing apps with Arkitekt. You can pick the one that suits your needs best.
Classic
This is the most straight-forward way of interacting with Arkitekt and its services if you want to interact and explore your data, and use functionality from other apps. The Arkitekt API here sits in the background just like any other python library, and you are in full control of the execution of your code.
from arkitekt import easy
from mikro.api.schema import from_xarray
import numpy as np
# whatever python code
with easy("my_little_app", url="http://localhost:8000"):
# do stuff with the arkitekt api
# new image
img = np.random.rand(100, 100)
image = from_xarray(img, name="my_image") # uploads image to the mikro service
# Whatever python code
This is a very simple example of how you can use the Arkitekt API to interact with the services. Here we are creating an "easy" app (more about that later) and then we are creating a new image and uploading it to the mikro service. Once we leave the context manager, the app is automatically closed and your script can continue to run as usual. Also you run this like any other python script, without any additional steps.
To get started with the classical style, you can follow the Classic Tutorial
Plugin
App that follow the integrated style
are more integrated into the Arkitekt ecosystem.
The Integrated style is your best choice if you want to provide new functionality (nodes)
and develop your own Arkitekt App. In the integrated style the Arkitekt CLI takes more control over your development process, ands streamline
the process of developing and your app publishing apps so that it can be used by other users.
from arkitekt import register
from mikro.api.schema import from_xarray, RepresentationFragment
@register
def create_random_image(x_size: int, y_size: int) -> RepresentationFragment:
""" Random Image
Creates a random image with the given size.
Parameters
----------
x_size : int
The size of the image in x direction.
y_size : int
The size of the image in y direction.
Returns
-------
RepresentationFragment
The created image.
"""
img = np.random.rand(100, 100)
return from_xarray(image, "Random Image")
if __name__ == "__main__":
# here you can run other code, that
# will not be executed when the app is
# run by the arkitekt cli
pass
Here we are creating an app that can be run by the Arkitekt CLI and that
provides a Node (Add two Numbers) that can be used by other apps. The
@register
decorator is used to mark a function as a node.
While you can run this script like any other python script ( executing the
if __name__ == "__main__"
block ) in the integrated style you are using
the Arkitekt CLI to run yout app via:
arkitekt run dev
The CLI will then create the App context for your app and register the functions
that are marked with the @register
decorator as nodes
This pattern might seem strange at first, but it has a few advantages, such as nice developer experience features like hot-reloading, but most importantly and easy portability of your app to other Arkitekt instances.
To get started with the integrated style, you can follow the Integrated Tutorial