Metadata-Version: 2.4
Name: atlascloudsdk
Version: 0.1.1
Summary: Python SDK for the Atlas API
Author: Atlas
License-Expression: MIT
Keywords: atlas,cloud,sdk,api
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.32.0
Requires-Dist: typer>=0.12.0
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Requires-Dist: ruff; extra == "dev"
Requires-Dist: mypy; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: twine; extra == "dev"
Requires-Dist: mkdocs-material; extra == "dev"
Dynamic: license-file

# Atlas Python SDK

Python SDK for managing Atlas resources through the Atlas API, including projects, networks, SSH keys, security groups, compute options, and virtual machines.

The SDK supports authenticated API connections, resource discovery, and virtual machine provisioning.

## Installation

Install the Atlas Python SDK:
```bash
pip install atlascloudsdk
```

Use TestPyPI only when testing a pre-release build.

Python 3.10 or newer is required.

The current SDK version is `0.1.1`.

## Create a Connection

Create one authenticated connection and reuse it for API calls.

```python
from atlas import Connection

with Connection(
    base_url="https://your-atlas-host",
    username="your-username",
    password="your-password",
) as client:
    projects = client.projects.list(
        enterprise_ref_key="ENTERPRISE_REF_KEY",
    )
    print(projects)
```

Replace the example URL and credentials with your Atlas environment details.

Applications that already have valid access and refresh tokens can initialize a connection without logging in again:

```python
from atlas import Connection

client = Connection.from_tokens(
    base_url="https://your-atlas-host",
    access_token="ACCESS_TOKEN",
    refresh_token="REFRESH_TOKEN",
)
```

## Discover Resources

Use the reference keys returned by each API response when requesting related resources. Replace the placeholder reference keys below with valid values from your environment.

```python
from atlas import Connection

with Connection(
    base_url="https://your-atlas-host",
    username="your-username",
    password="your-password",
) as client:
    projects = client.projects.list(
        enterprise_ref_key="ENTERPRISE_REF_KEY",
    )

    networks = client.networks.list(
        project_ref_key="PROJECT_REF_KEY",
    )

    ssh_keys = client.ssh_keys.list(
        project_ref_key="PROJECT_REF_KEY",
    )

    security_groups = client.security_groups.list(
        project_ref_key="PROJECT_REF_KEY",
    )

    operating_systems = (
        client.compute_units.list_operating_systems()
    )

    versions = client.compute_units.list_versions(
        os_ref_key="OS_REF_KEY",
    )

    flavours = client.compute_units.list_flavours(
        version_ref_key="VERSION_REF_KEY",
    )

    print("Projects:", projects)
    print("Networks:", networks)
    print("SSH keys:", ssh_keys)
    print("Security groups:", security_groups)
    print("Operating systems:", operating_systems)
    print("Versions:", versions)
    print("Flavours:", flavours)
```

The API responses contain resource information, including reference keys where provided. Use the appropriate `ref_key` for subsequent operations. The SDK does not automatically select resources for you.

## Provision a Virtual Machine

To create a virtual machine, provide valid project, SSH key, network, security group, and compute flavour reference keys, along with the other required provisioning parameters.

```python
from atlas import Connection

with Connection(
    base_url="https://your-atlas-host",
    username="your-username",
    password="your-password",
) as client:
    machine_name = "training-vm"

    # Confirm the return semantics of this method in your SDK version.
    is_name_available = client.instances.validate_machine_name(
        project_ref_key="PROJECT_REF_KEY",
        machine_name=machine_name,
    )

    if not is_name_available:
        raise ValueError(
            f"Machine name is already in use: {machine_name}"
        )

    payload = {
        "project_ref_key": "PROJECT_REF_KEY",
        "secret_ref_key": "SSH_SECRET_REF_KEY",
        "network_ref_key": "NETWORK_REF_KEY",
        "security_ref_key": "SECURITY_GROUP_REF_KEY",
        "compute_ref_key": "FLAVOUR_REF_KEY",
        "is_public_ip": False,
        "bandwidth": 0,
        "machine_name": machine_name,
        "additional_storage": {"name": "", "size": 0},
        "root_disk": 15,
        "ai_services": [],
        "platform_services": [],
        "addons": [],
        "license": {"name": "", "type": 0},
        "time": 31,
        "custom_flavour": "",
    }

    result = client.instances.create_vm(payload)
    print(result)
```

Replace all placeholder reference keys with valid values returned by the relevant APIs. Configure the disk size, billing duration, networking, and optional services according to your requirements.

**Note:** Provisioning is asynchronous. A successful response may indicate that the request was accepted, but it does not necessarily mean the virtual machine is ready. Use the instance list or get operations to inspect the result.

## Error Handling

The SDK provides exceptions for handling API failures. The following example illustrates the pattern; use only exception classes available in your installed SDK version.

```python
from atlas.exceptions import (
    AtlasError,
    AuthenticationError,
    NotFoundError,
    ValidationError,
)

try:
    # Call an SDK resource method here.
    pass

except AuthenticationError:
    print("Authentication failed. Check your credentials.")

except ValidationError as error:
    print("Validation failed:", error.details)

except NotFoundError:
    print("Resource was not found.")

except AtlasError as error:
    print("Status code:", error.status_code)
    print("Details:", error.details)
```

## Security

- Never commit passwords, access tokens, refresh tokens, private keys, or API secrets to source control.
- Use HTTPS for production API communication.
- Store credentials in environment variables or a secure secrets manager.
- Keep downloaded SSH private keys secure and never print or log them.
