User-side Python SDK for downloading datasets and assets from Cortexa
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):
- Function parameters (passed directly to
download_dataset) - Config file (
~/.cortexa/config.json) - Environment variables
Example config file (auto-generate with cortexa-sdk --init-config):
{
"api_key": "your-api-key",
"base_url": "https://your-cortexa-server/api",
"dataset_dir": "~/datasets"
}
Environment variables:
CORTEXA_API_KEY– API keyCORTEXA_BASE_URL– Base URL of the Cortexa serverCORTEXA_DATASET_DIR– Default dataset download directoryCORTEXA_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
path = download_dataset(
dataset_id="DATASET_ID",
export_type=ExportType.JSON,
api_key="YOUR_API_KEY",
base_url="https://your-cortexa-server/api",
download_dir="~/datasets"
)
print("Dataset saved to", path)
2. Use config file or environment variables (lower precedence):
from cortexa_sdk import download_dataset, ExportType
path = download_dataset("DATASET_ID", export_type=ExportType.JSON)
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 JSON
cortexa-sdk -d "DATASET_ID" \
--export-type JSON \
--api-key TOKEN \
--base-url http://localhost:8000/api/v1 \
--download-dir ./tmp/datasets
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",
)
Configuration Resolution Order
- Parameters passed to
download_dataset - Values from the config file (
~/.cortexa/config.jsonor as set byCORTEXA_CONFIG) - 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-sdkcommand).
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
- Install build tools:
pip install --upgrade setuptools build twine
- Build the package:
python -m build
- Upload to PyPI:
twine upload dist/*
- Tag and push the release in git:
git tag v<version> git push --tags
- (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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cortexa_sdk-0.1.3.tar.gz.
File metadata
- Download URL: cortexa_sdk-0.1.3.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d60ef608720f57bb0a9b94adca0082861c3d1924b64a60118620928507d1c383
|
|
| MD5 |
348f89f7b31bd5397b7b0efd9870dfe1
|
|
| BLAKE2b-256 |
e83e5ecce5b2373716c646d5e7b7e6cc333fc232c1d60b803ff2dd244c485cde
|
File details
Details for the file cortexa_sdk-0.1.3-py3-none-any.whl.
File metadata
- Download URL: cortexa_sdk-0.1.3-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b20076f2dd4010a7b6cf7719412c5cacfd37005111a9c440a744e68369cd1897
|
|
| MD5 |
d0ef6bf789d1a14bee21e7838bdf5f18
|
|
| BLAKE2b-256 |
c01d7ea661bd19de04a31bc6f9b72d770c593b043a29e99351a64904ff430c72
|