> For the complete documentation index, see [llms.txt](https://wiki.simpler.grants.gov/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.simpler.grants.gov/product/api/simpler-grants-api-tutorial/lets-make-a-python-script-to-use-the-api/next-steps-optional.md).

# Next Steps (optional)

Now that you have a working script to access the Simpler.Grants.gov API let's make some changes and see how it effects the response data.

* Change `page_size` to 25 to see more results per request
* Replace `"health"` with you own keyword(s), e.g. `"education"` or `"rural broadband"`
* When you run the script, try piping the output to a file to easily save it. `python3 search_opportunities.py > results.txt`

## Next-step ideas to level up your script

### Read the API key from an environment variable

It is safer than hard-coding your API key into the script. Try adding this import and variable to the top of your script.

```python
import os
API_KEY = os.getenv("SGG_API_KEY", "")
```

Then when you run it, you first need to add your API key to the environment:

{% tabs %}
{% tab title="Windows(PowerShell)" %}

```powershell
$env:SGG_API_KEY='your_key_here'
```

{% endtab %}

{% tab title="macOS/Linux" %}

```bash
export SGG_API_KEY=your_key_here
```

{% endtab %}
{% endtabs %}

### Add a real command-line interface

Try adding these changes to your code so that users can pass query, page size and sort options without needing to edit the code.

```python
import argparse

def parse_args():
    p = argparse.ArgumentParser()
    p.add_argument("query", nargs="*", help="optional keywords")
    p.add_argument("--page-size", type=int, default=10)
    p.add_argument("--sort-by", default="post_date")
    p.add_argument("--sort-dir", choices=["ascending","descending"], default="descending")
    return p.parse_args()

if __name__ == "__main__":
    args = parse_args()
    term = " ".join(args.query)
    search_opportunities(term, page_size=args.page_size, order_by=args.sort_by, sort_direction=args.sort_dir)

```

You could then run the script with command line arguments like `python search_opportunities.py health --sort-dir ascending`


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://wiki.simpler.grants.gov/product/api/simpler-grants-api-tutorial/lets-make-a-python-script-to-use-the-api/next-steps-optional.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
