# Usage

You can easily import this library using:

```python
from pynytimes import NYTAPI
```

Then you can simply add your API key (get your API key from [The New York Times Dev Portal](https://developer.nytimes.com/)):

```python
nyt = NYTAPI("Your API key", parse_dates=True)
```

**Make sure that if you commit your code to GitHub you** [**don't accidentially commit your API key**](https://towardsdatascience.com/how-to-hide-your-api-keys-in-python-fb2e1a61b0a0)**.**

The following parameters can be set, only the `key` parameter is required.

## Parameters

| Variables     | Description                                                                     | Data type                   | Required | Default               |
| ------------- | ------------------------------------------------------------------------------- | --------------------------- | -------- | --------------------- |
| `key`         | The API key from [The New York Times](https://developer.nytimes.com/)           | `str`                       | True     | `None`                |
| `https`       | Use [HTTPS](https://en.wikipedia.org/wiki/HTTPS)                                | `bool`                      | False    | `True`                |
| `session`     | Optionally set your own `request.session`                                       | `requests.sessions.Session` | False    | `requests.Session()`  |
| `backoff`     | Enable [exponential backoff](https://en.wikipedia.org/wiki/Exponential_backoff) | `bool`                      | False    | `True`                |
| `user_agent`  | Set the [User Agent](https://en.wikipedia.org/wiki/User_agent)                  | `str`                       | False    | `pynytimes/[version]` |
| `parse_dates` | Enable the parsing of dates into `datetime.datetime` or `datetime.date` objects | `bool`                      | False    | `False`               |


---

# 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://pynytimes.michadenheijer.com/getting-started/usage.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.
