> For the complete documentation index, see [llms.txt](https://docs.licensespring.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.licensespring.com/sdks/python-sdk/python-hardware-device-ids.md).

# Python Hardware (Device) IDs

This library provides preconfigured hardware identity providers:

* `HardwareIdProvider` (default)
* `PlatformIdProvider`
* `HardwareIdProviderSource` (recommended)

You can set the desired hardware identity provider when initializing the APIClient:

{% code title="example.py" %}

```python
from licensespring.hardware import PlatformIdProvider

api_client = APIClient(api_key="_your_api_key_", shared_key="_your_shared_key_", hardware_id_provider=PlatformIdProvider)
```

{% endcode %}

It also supports their customization and creation of your own hardware id provider.

{% hint style="warning" %}
On the next major version release `HardwareIdProviderSource` will be set as the **default** `hardware_id_provider`.
{% endhint %}

#### HardwareIdProvider

Uses [**uuid.getnode()**](https://docs.python.org/3/library/uuid.html#uuid.getnode) to generate unique ID per device as described:

> Get the hardware address as a 48-bit positive integer. The first time this runs, it may launch a separate program, which could be quite slow. If all attempts to obtain the hardware address fail, we choose a random 48-bit number with the multicast bit (least significant bit of the first octet) set to 1 as recommended in RFC 4122. “Hardware address” means the MAC address of a network interface. On a machine with multiple network interfaces, universally administered MAC addresses (i.e. where the second least significant bit of the first octet is unset) will be preferred over locally administered MAC addresses, but with no other ordering guarantees.

All of the methods exposed by `HardwareIdProvider`:

{% code title="hardware\_id\_provider.py" %}

```python
class HardwareIdProvider:
    def get_id(self):
        return str(uuid.getnode())

    def get_os_ver(self):
        return platform.platform()

    def get_hostname(self):
        return platform.node()

    def get_ip(self):
        return socket.gethostbyname(self.get_hostname())

    def get_is_vm(self):
        return False

    def get_vm_info(self):
        return None

    def get_mac_address(self):
        return ":".join(("%012X" % uuid.getnode())[i : i + 2] for i in range(0, 12, 2))

    def get_request_id(self):
        return str(uuid.uuid4())
```

{% endcode %}

#### HardwareIdProviderSource

Utilizes a proprietary [**in-house algorithm**](https://pypi.org/project/licensespring-hardware-id-generator/) for our SDKs

{% code title="hardware\_id\_provider\_source.py" %}

```python
class HardwareIdProviderSource(HardwareIdProvider):
    def get_id(self):   
        hardware_id = get_hardware_id(HardwareIdAlgorithm.Default)
        
        if logging.getLogger().hasHandlers():
            logs = get_logs()
            version = get_version()
            logging.info("Version: ",version)
            logging.info("Hardware ID:",hardware_id)
            for log_line in logs:
                logging.info(log_line)
    
        return hardware_id
```

{% endcode %}

#### Customization

Extend any of the preconfigured hardware identity providers, overwrite the methods you want and provide it when initializing the APIClient:

{% code title="custom\_hardware\_id\_provider.py" %}

```python
class CustomHardwareIdProvider(HardwareIdProvider):
    def get_id(self):
        return "_my_id_"

api_client = APIClient(api_key="_your_api_key_", shared_key="_your_shared_key_", hardware_id_provider=CustomHardwareIdProvider)
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.licensespring.com/sdks/python-sdk/python-hardware-device-ids.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
