# Python

## Python 3

Example using `requests_oauthlib` package

### Base oauth client

```python
import json
from requests_oauthlib import OAuth1Session

client = OAuth1Session('PROVIDEDKEYHERE',
                       client_secret='PROVIDEDSECRETHERE')
base_url = 'https://yourbrand.cloudfrontend.net/api/v2/'
```

### `GET` request

Example fetching a list of Sites.

```python
response = client.get(
    '{}sites/'.format(base_url),
    params={
        'deleted': 0,
    })
content = response.json()
```

### `POST` request

Creating a new site using a JSON object containing the payload.

```python
payload = {
    'formatted_domain': 'www.somebusinessname.com',
    ...
}
response = client.post(
    '{}sites/'.format(base_url),
    json=payload)
content = response.json()
```

## Python 2

Example using `oauth2` library

### `GET` request

```python
import json
import oauth2 as oauth

consumer = oauth.Consumer('PROVIDEDKEYHERE', 'PROVIDEDSECRETHERE')
client = oauth.Client(consumer, None)
response, content = client.request('/api/v2/sites/', 'GET', headers={
    'content-type': 'application/json'
})
content = json.loads(content)
```

### `POST` request

A JSON object containing the parameters is encoded as a string and then passed as the request body.

```python
import json
import oauth2 as oauth

consumer = oauth.Consumer('PROVIDEDKEYHERE', 'PROVIDEDSECRETHERE')
client = oauth.Client(consumer, None)
params = {
    'domain': 'somebusinessname.com',
    ...
}
response, content = client.request('/api/v2/sites/', 'POST', body=json.dumps(params), headers={
    'Content-Type': 'application/json'
})
content = json.loads(content)
```


---

# 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://api-docs.devhub.com/code-examples/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.
