Metadata-Version: 2.5
Name: urlquery-api
Version: 0.8.0
Summary: Python client for the urlquery v2 API: URL analysis reports, search, reputation, Host Profile, YARA and monitoring
Project-URL: Homepage, https://urlquery.net
Project-URL: Documentation, https://docs.urlquery.net/docs/libraries/python
Project-URL: Source, https://github.com/urlquery/urlquery-api-python
Project-URL: Issues, https://github.com/urlquery/urlquery-api-python/issues
Author-email: "urlquery.net" <contact@urlquery.net>
License-Expression: MIT
License-File: LICENSE
Keywords: phishing,sandbox,threat intelligence,url analysis,urlquery,yara
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Security
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: httpx>=0.27
Requires-Dist: pydantic>=2.7
Provides-Extra: test
Requires-Dist: pytest>=8; extra == 'test'
Description-Content-Type: text/markdown

# urlquery-api-python

[![PyPI](https://img.shields.io/pypi/v/urlquery-api)](https://pypi.org/project/urlquery-api/)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue)](LICENSE)

The Python client for the [urlquery](https://urlquery.net) v2 API. urlquery
analyzes URLs in an isolated browser and records what they do: redirects,
HTTP traffic, scripts, downloads, detections and a screenshot.

With this package you can submit URLs and wait for the reports, read and
compare reports, search a year of reports, look up reputation, explore Host
Profile, and manage YARA rules, watchlists and page monitors. Results are
typed [pydantic](https://docs.pydantic.dev) models.

**Documentation: <https://docs.urlquery.net/docs/libraries/python>**

## Install

```sh
pip install urlquery-api
```

It needs Python 3.10 or later, and an API key from your
[urlquery.net](https://urlquery.net) account.

## Example

```python
from urlquery_api import Client

with Client() as client:  # the API key from URLQUERY_APIKEY
    # Analyze a URL as a restricted report and wait for it.
    s = client.submit("https://example.com/login", access="restricted", wait=True)

    # The full report: every HTTP transaction, script and artifact.
    report = client.report(s.report_id)
    for t in report.http:
        print(t.response.status_code, t.url.addr)

    # Every other report that loaded the same scripts.
    for script in report.javascript.script:
        for hit in client.iter_search_results(f"javascript.script.sha256:{script.sha256}"):
            print(script.sha256[:12], hit.report_id, hit.url.addr)
```

## How it behaves

- **Typed results.** The models in `urlquery_api.models` are generated from
  the API's [OpenAPI description](https://docs.urlquery.net/openapi/public-v2.yaml),
  so every field of every response, down to the report's transactions,
  scripts and artifacts, is typed.
- **Paging.** Each list method returns one page; its `iter_…` method yields
  every item, following cursors for you.
- **Rate limits and retries.** A call waits out a rate limit for its
  `Retry-After`, and a GET is retried after a server error or a network
  failure; `max_retry_wait` bounds the waiting. Submissions are never retried
  once they may have been queued.
- **Waiting for an analysis.** `submit(..., wait=True)` and
  `wait_for_submission` poll until the analysis is done or has failed; on a
  timeout, `WaitTimeoutError.submission` is the last state, with the queue and
  report IDs.
- **Errors.** API errors raise `APIError` with the API's error `code`, such as
  `NOT_FOUND` or `RATE_LIMIT_EXCEEDED`.
- **Hostile content.** Report content comes from the analyzed sites: treat
  titles, scripts and downloads as untrusted data.

## Contributing

Report bugs and ask for features in the
[issues](https://github.com/urlquery/urlquery-api-python/issues). Pull requests
are welcome: this repository is published from urlquery's main repository, so
an accepted change is applied there and arrives here with the next release.
`src/urlquery_api/models.py` is generated from the API description; don't
edit it by hand. For other questions, write to
[contact@urlquery.net](mailto:contact@urlquery.net).

```sh
pip install -e '.[test]'
pytest
```

## License

MIT © [urlquery.net](https://urlquery.net), see [LICENSE](LICENSE).
