Skip to main content

User-side Python SDK for downloading datasets and assets from Cortexa. Now use 'annotation_type' parameter (rect, polygon) for YOLO.

Project description

Cortexa SDK

The Cortexa SDK is a Python client for downloading datasets from a Cortexa server, supporting both programmatic and CLI usage.

Installation

pip install cortexa-sdk

Configuration

You can configure the SDK in three ways (precedence: function parameters > config file > environment variables):

  1. Function parameters (passed directly to download_dataset)
  2. Config file (~/.cortexa/config.json)
  3. Environment variables

Example config file (auto-generate with cortexa-sdk --init-config):

{
  "api_key": "your-api-key",
  "base_url": "http://your-cortexa-server/api/v1",
  "dataset_dir": "~/datasets"
}

Environment variables:

  • CORTEXA_API_KEY – API key
  • CORTEXA_BASE_URL – Base URL of the Cortexa server
  • CORTEXA_DATASET_DIR – Default dataset download directory
  • CORTEXA_CONFIG – Path to a JSON config file (defaults to ~/.cortexa/config.json)

Usage

Python API:

You can use the SDK in two ways:

1. Pass all parameters explicitly (highest precedence):

from cortexa_sdk import download_dataset, ExportType, AnnotationType

path = download_dataset(
    dataset_id="DATASET_ID",
    export_type=ExportType.JSON,
    annotation_type=AnnotationType.RECT,
    api_key="YOUR_API_KEY",
    base_url="http://your-cortexa-server/api/v1",
    download_dir="~/datasets",
    assets_included=True
)
print("Dataset saved to", path)

2. Use config file or environment variables (lower precedence):

from cortexa_sdk import download_dataset, ExportType, AnnotationType

path = download_dataset("DATASET_ID", export_type=ExportType.JSON, annotation_type=AnnotationType.RECT)
print("Dataset saved to", path)

In this case, the SDK will read values from ~/.cortexa/config.json or environment variables if parameters are not provided.

CLI:

cortexa-sdk --init-config  # Generate default config file if needed
cortexa-sdk -d "DATASET_ID" --export-type YOLO --annotation-type rect
cortexa-sdk -d "DATASET_ID" \
  --export-type JSON \
  --annotation-type rect \
  --api-key TOKEN \
  --base-url http://localhost:8000/api/v1 \
  --download-dir ./tmp/datasets \
  --assets-included True

Example output:

Created download task for dataset 688a26a52b1a60e8375b98d7
Created dataset download task 688a79d2b3c851acb0606df6 for 688a26a52b1a60e8375b98d7
dataset task 688a79d2b3c851acb0606df6 status: PROCESSING progress: 40%
... (progress updates) ...
dataset task 688a79d2b3c851acb0606df6 status: COMPLETED progress: 100%
Downloading dataset from ...
Saved dataset to tmp/datasets/688a26a52b1a60e8375b98d7.zip

Examples

Using environment variables:

export CORTEXA_API_KEY="TOKEN"
export CORTEXA_BASE_URL="https://api.example.com/api/v1"
python - <<'PY'
from cortexa_sdk import download_dataset
download_dataset("dataset123")
PY

Using a config file:

from cortexa_sdk import download_dataset, ExportType
path = download_dataset("dataset123", export_type=ExportType.COCO)
print(path)

Overriding with parameters:

from cortexa_sdk import download_dataset, ExportType

download_dataset(
    "dataset123",
    export_type=ExportType.COCO,
    api_key="TOKEN",
    base_url="https://api.example.com/api/v1",
    download_dir="/tmp/datasets",
    assets_included=True,
)

Configuration Resolution Order

  1. Parameters passed to download_dataset
  2. Values from the config file (~/.cortexa/config.json or as set by CORTEXA_CONFIG)
  3. Environment variables

Project Structure

The main files and folders for the Cortexa SDK project are organized as follows:

cortexa-sdk-project/
│
├── pyproject.toml                # Project metadata and build configuration
├── README.md                     # This documentation file
├── test-download.py              # Example/test script for dataset download
├── cortexa_sdk/                  # SDK source code package
│   ├── __init__.py               # SDK main logic and API
│   └── cli.py                    # Command-line interface entry point
│
└── ... (other files and folders)
  • pyproject.toml: Defines the package, dependencies, and CLI entry point.
  • README.md: Documentation for installation, configuration, usage, and development.
  • test-download.py: Example script to demonstrate SDK usage for downloading datasets.
  • cortexa_sdk/: The main SDK Python package.
    • __init__.py: Implements the SDK API (e.g., download_dataset).
    • cli.py: Implements the CLI (cortexa-sdk command).

You can run the CLI directly after installation:

cortexa-sdk --help

Or use the SDK in your own Python scripts as shown in the usage examples above.

Releasing to PyPI

  1. Install build tools:
    pip install --upgrade setuptools build twine
    
  2. Build the package:
    python -m build
    
  3. Upload to PyPI:
    twine upload dist/*
    
  4. Tag and push the release in git:
    git tag v<version>
    git push --tags
    
  5. (Optional) Test uploads using TestPyPI with twine.

Rebuild and reinstall locally:

python -m build
pip install dist/cortexa_sdk-*.whl --force-reinstall

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cortexa_sdk_duan-0.1.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cortexa_sdk_duan-0.1.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file cortexa_sdk_duan-0.1.0.tar.gz.

File metadata

  • Download URL: cortexa_sdk_duan-0.1.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for cortexa_sdk_duan-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d664692ef4d887494a73c803b6d1a6a4cc450273e6d9d1383f98b33eb48d7d94
MD5 b7b4aae315a9458f574a14868a1033b3
BLAKE2b-256 864568924df0fb8cf48fa1999f201649750734cab99d2373df2d77f0e44bc841

See more details on using hashes here.

File details

Details for the file cortexa_sdk_duan-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for cortexa_sdk_duan-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 10727b0c66cab27a28ddf234dd78b1bc038b3aeb6494315f7d511af6e8555130
MD5 6f80de4b26aaf1e6b9dbc19104f711e3
BLAKE2b-256 3bb6273788ff07159e51bef54a993f1283592bdf3610c0f8984247388df5d9e7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page