Using the darwin-py Dockerfile
This guide will walk you through the steps required to build and run darwin-py as a Docker container. The darwin-py package provides a Python SDK and CLI to interact with the V7 Darwin platform, and this Dockerfile helps you set up a consistent environment for its use.
Prerequisites
Before you begin, ensure you have the following installed on your system:
- Docker (Docker Engine)
- Docker Compose (optional, for complex multi-container setups)
1. Obtain the Dockerfile
You can find the Dockerfile in the darwin-py repository from versions 1.0.4 onward. Clone the repository or download the Dockerfile to your working directory:
git clone https://github.com/v7labs/darwin-py.git
cd darwin-pyEnsure the Dockerfile is located in your working directory:
ls
Dockerfile pyproject.toml poetry.lock ...2. Build the Docker Image
To build the Docker image, open a terminal in the directory containing the Dockerfile and run the following command:
docker build -t darwin-py .-t darwin-py: This tags the image with the name darwin-py, making it easier to reference later
The build process will:
- Install necessary build tools
- Install Python dependencies using Poetry
- Install the darwin-py package and CLI
3. Customise the Dockerfile
If you have specific requirements, you can customise the Dockerfile before building:
- Copy across files: Uncomment and modify the
COPY . /appline to include any local files you might need, such as files to upload to datasets, annotations to import, or credentials for authenticating - Expose Ports: Uncomment and modify the
EXPOSEline to expose any necessary ports
4. Authenticate
Almost all darwin-py functionality requires that you are authenticated with a particular Darwin team you wish to interact with. You can authenticate by:
- Creating a client directly from an API key:
from darwin.client import Client
API_KEY = "YOUR_API_KEY_HERE"
client = Client.from_api_key(API_KEY)- From your
~/.darwin/config.yamlfile. If you've useddarwin-pybefore, you can copy across your config file to the container:
from darwin.client import Client
client = Client.local(team_slug='team_slug')- Via the CLI command,
darwin authenticate:
>darwin authenticate
API key:
Make {team_slug} the default team? [y/N] y
Datasets directory [~/.darwin/datasets]:
Authentication succeeded.Updated about 1 month ago
