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

# Python

In Python, we'll be using the `requests` library to send HTTP requests. Here's how you can use the book search API with Python:

First, make sure you import the necessary library at the top of your file:

```python
import requests
import os
import json
```

Then, you can use the following code to make the API request:

```python
def search_book(query):
    url = "https://api.promptjoy.com/api/mVMCpq"
    headers = {
        'Content-Type': 'application/json',
        'x-api-key': os.getenv('PROMPTJOY_API_KEY')
    }
    data = {
        'query': query
    }
    response = requests.post(url, headers=headers, data=json.dumps(data))

    if response.status_code == 200:
        return response.json()
    else:
        raise Exception(f"Request failed with status {response.status_code}")

```

\
You can call this function with the search term as follows:

```python
search_result = search_book("your_search_term")
print(search_result)

```

Replace `"your_search_term"` with the book you're searching for. This function will return a dictionary of the search results.

This example uses the `requests` library, which is a popular choice for making HTTP requests in Python. If you haven't installed it yet, you can do so with `pip install requests`.

Remember to handle exceptions and errors as needed in your actual application code.

Note: In this example, the API key is retrieved from environment variables for security reasons. Ensure that you've set the `PROMPTJOY_API_KEY` environment variable in your environment where this code will be executed.

\
\ <br>
