# Python

Требуемые библиотеки:

| Библиотека | Версия |
| ---------- | ------ |
| requests   | 2.27.1 |

Код SDK:

```python
import requests

class PureServers:
    def __init__(self, email, password):
        self.email = email
        self.password = password
        self.session = None

    def request(self, url, method, data=None, secured=False):
        if data is None:
            data = {}
        
        headers = {}
        if secured and self.session:
            headers['session'] = self.session

        try:
            if method == 'POST':
                res = requests.post(f'https://cp.pureservers.org/api/{url}', json=data, headers=headers)
            elif method == 'GET':
                res = requests.get(f'https://cp.pureservers.org/api/{url}', headers=headers)
            else:
                raise ValueError("Unsupported method")

            res.raise_for_status()

            if 'session' in res.headers:
                self.session = res.headers['session']

            return {'data': res.json(), 'headers': res.headers, 'success': True}
        except requests.RequestException as e:
            return {'data': e.response.json() if e.response else "No response", 'headers': e.response.headers if e.response else {}, 'success': False}

    def login(self):
        res = self.request('auth/login', 'POST', {'email': self.email, 'password': self.password})
        if res['success']:
            return True
        return res
```

Пример использования с получением списка серверов:

```python
email = "<email>"
password = "<password>"
api = PureServers(email, password)

login = api.login()
if login == True:
    servers_list = api.request('servers/list', 'GET', {}, True)
    print(servers_list)
else:
    print("Login failed", login_result)
```


---

# 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://docs.pureservers.org/sdk/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.
