{"library":"openxlab","code":"import os\nfrom openxlab.xlab.handler.user_token import get_jwt\nfrom openxlab.dataset import get\n\n# Set your Access Key and Secret Key as environment variables\n# These can be obtained from your OpenXLab user center.\n# For example: export OPENXLAB_AK=\"YOUR_AK_HERE\"\n# For example: export OPENXLAB_SK=\"YOUR_SK_HERE\"\nak = os.environ.get('OPENXLAB_AK', 'YOUR_AK_HERE')\nsk = os.environ.get('OPENXLAB_SK', 'YOUR_SK_HERE')\n\nif ak == 'YOUR_AK_HERE' or sk == 'YOUR_SK_HERE':\n    print(\"Please set OPENXLAB_AK and OPENXLAB_SK environment variables or replace placeholders.\")\n    # Attempt to use CLI config if env vars are not set for demonstration purposes\n    # In a real scenario, user would run 'openxlab config' or set env vars.\n    # For programmatic access, env vars are preferred.\nelse:\n    try:\n        # Authenticate and get a JWT token\n        token = get_jwt(ak=ak, sk=sk)\n        print(f\"Successfully obtained JWT token (first 10 chars): {token[:10]}...\")\n\n        # Example: Get (download) a public dataset\n        # Replace 'OpenDataLab/MNIST' with a valid dataset repository and adjust target_path\n        # Ensure the target_path exists or can be created.\n        dataset_repo_name = 'OpenDataLab/MNIST'\n        target_download_path = './MNIST_dataset'\n        print(f\"\\nAttempting to download dataset: {dataset_repo_name} to {target_download_path}\")\n        \n        # Create a dummy directory for download if it doesn't exist\n        os.makedirs(target_download_path, exist_ok=True)\n\n        # Note: The 'get' function might automatically use configured AK/SK,\n        # but explicit authentication often precedes other SDK calls.\n        get(dataset_repo=dataset_repo_name, target_path=target_download_path)\n        print(f\"Dataset '{dataset_repo_name}' downloaded to '{target_download_path}' successfully.\")\n\n    except Exception as e:\n        print(f\"An error occurred: {e}\")\n        print(\"Ensure your AK/SK are correct and you have network access to OpenXLab.\")\n","lang":"python","description":"This quickstart demonstrates how to authenticate with OpenXLab using environment variables for Access Key (AK) and Secret Key (SK), and then how to use the `openxlab.dataset.get` function to download a public dataset. Replace 'YOUR_AK_HERE' and 'YOUR_SK_HERE' with your actual credentials, or ideally, set them as environment variables (OPENXLAB_AK, OPENXLAB_SK). The example attempts to download the 'OpenDataLab/MNIST' dataset, which is a common public dataset.","tag":null,"tag_description":null,"last_tested":"2026-04-24","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}