# Python

The Panda Authentication System is designed to seamlessly integrate with Python development, offering robust user authentication and security features. Tailored specifically for Python developers, Panda Authentication provides easy implementation of user registration, login, and key management functionalities. Whether you're building a web service or an application, Panda Authentication ensures smooth integration and enhanced security for your users.

⚠️ WARNING: This Documentation is Outdated. We're currently Updating the Library for New Python Version.

### Python Code / Documentation:

<pre class="language-python"><code class="lang-python">import requests
import hashlib

#Replace the Identifier with your own identifier
identifier = "pandadevkit" 

#Get your API Token on Hub Settings (Required) For Security only
APIToken = ""

#--------------------------------------------------
# We use IP Address as our HWID, You can replace it with UUID / Hardware ID &#x26; etc as long you
# have knowledge of Python.
#--------------------------------------------------
def fetch_ip():
    response = requests.get(f"https://pandadevelopment.net/serviceapi?service={identifier}&#x26;command=getuseripaddress")
    if response.status_code == 200:
        return response.text.strip()  # Return the raw text response
    else:
        return None

def hash_ip(ip_address):
    return hashlib.sha256(ip_address.encode()).hexdigest()
#--------------------------------------------------
#Function ( Get the Key URL )
#--------------------------------------------------
def generate_key():
    hwid = hash_ip(fetch_ip())
    url = f"https://pandadevelopment.net/getkey?hwid={hwid}&#x26;service={identifier}"
    return url

#--------------------------------------------------
#Function ( Validate the Key alongside with the Hardware ID )   
#--------------------------------------------------
def validate_key_hwid(key, hwid):
    url = f"https://pandadevelopment.net/v2_validation?hwid={hwid}&#x26;service={identifier}&#x26;key={key}"
    response = requests.get(url)
    if response.status_code == 200:
        print("Raw response from validate_key_hwid:", response.text)  # Debugging line
        try:
            return response.json()
        except requests.exceptions.JSONDecodeError as e:
            print("JSON decode error:", e)
            return None
    else:
        return None
#--------------------------------------------------
#Example Code ( You can run this on console )
<strong>#--------------------------------------------------
</strong>def main():
    print("Generated Key URL: " + generate_key())
    key = input("Enter your key: ")
    hwid = hash_ip(fetch_ip())

    validation_response = validate_key_hwid(key, hwid)
    if validation_response:
        v2_authentication = validation_response.get("V2_Authentication", "Not Found")
        key_info = validation_response.get("Key_Information", {})
        expires_at = key_info.get("expiresAt", "Not Found")
        premium_mode = key_info.get("Premium_Mode", "Not Found")

        print(f"V2_Authentication: {v2_authentication}")
        print(f"Expires At: {expires_at}")
        print(f"Premium Mode: {premium_mode}")
    else:
        print("Failed to validate key and HWID.")

if __name__ == "__main__":
    main()

</code></pre>


---

# Agent Instructions: 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://doc.pandadevelopment.net/utilizing-panda-auth-on-your-product/python.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.
