urlscan-python 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. urlscan_python-0.0.1/.github/workflows/docs.yml +32 -0
  2. urlscan_python-0.0.1/.github/workflows/publish.yml +26 -0
  3. urlscan_python-0.0.1/.github/workflows/test.yml +41 -0
  4. urlscan_python-0.0.1/.gitignore +179 -0
  5. urlscan_python-0.0.1/.lefthookrc +5 -0
  6. urlscan_python-0.0.1/LICENSE +21 -0
  7. urlscan_python-0.0.1/PKG-INFO +98 -0
  8. urlscan_python-0.0.1/README.md +80 -0
  9. urlscan_python-0.0.1/docs/README.md +1 -0
  10. urlscan_python-0.0.1/docs/dev.md +42 -0
  11. urlscan_python-0.0.1/docs/references/client.md +1 -0
  12. urlscan_python-0.0.1/docs/references/errors.md +3 -0
  13. urlscan_python-0.0.1/docs/references/iterator.md +1 -0
  14. urlscan_python-0.0.1/examples/screenshot_to_pil.py +45 -0
  15. urlscan_python-0.0.1/examples/search_and_download_screenshots.py +53 -0
  16. urlscan_python-0.0.1/examples/search_to_dataframe.py +58 -0
  17. urlscan_python-0.0.1/examples/search_to_network_graph.ipynb +145 -0
  18. urlscan_python-0.0.1/lefthook.yml +27 -0
  19. urlscan_python-0.0.1/mkdocs.yml +38 -0
  20. urlscan_python-0.0.1/pyproject.toml +86 -0
  21. urlscan_python-0.0.1/requirements.txt +1 -0
  22. urlscan_python-0.0.1/scripts/convert_to_pep440_version.py +13 -0
  23. urlscan_python-0.0.1/src/urlscan/__init__.py +10 -0
  24. urlscan_python-0.0.1/src/urlscan/_version.py +1 -0
  25. urlscan_python-0.0.1/src/urlscan/_version.pyi +1 -0
  26. urlscan_python-0.0.1/src/urlscan/client.py +652 -0
  27. urlscan_python-0.0.1/src/urlscan/error.py +27 -0
  28. urlscan_python-0.0.1/src/urlscan/iterator.py +91 -0
  29. urlscan_python-0.0.1/src/urlscan/types.py +6 -0
  30. urlscan_python-0.0.1/src/urlscan/utils.py +6 -0
  31. urlscan_python-0.0.1/tests/__init__.py +0 -0
  32. urlscan_python-0.0.1/tests/conftest.py +0 -0
  33. urlscan_python-0.0.1/tests/test_client.py +356 -0
  34. urlscan_python-0.0.1/tests/test_utils.py +19 -0
  35. urlscan_python-0.0.1/tests/test_version.py +5 -0
  36. urlscan_python-0.0.1/uv.lock +1355 -0
@@ -0,0 +1,32 @@
1
+ name: Publish docs
2
+
3
+ on:
4
+ release:
5
+ types: ["created"]
6
+
7
+ jobs:
8
+ deploy:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v4
12
+ with:
13
+ fetch-depth: 0 # fetch all commits/branches (otherwise "mike deploy" fails)
14
+ - uses: actions/setup-python@v5
15
+ with:
16
+ python-version: 3.13
17
+ cache: "pip"
18
+ - run: pip install -r requirements.txt
19
+ - uses: actions/cache@v4
20
+ with:
21
+ path: ~/.cache/uv
22
+ key: uv-3.13-${{ hashFiles('uv.lock') }}
23
+ - run: uv sync --frozen
24
+ - name: git config for "mike deploy"
25
+ run: |
26
+ git config --global user.name "${{ github.actor }}"
27
+ git config --global user.email "${{ github.actor }}@users.noreply.github.com"
28
+ - name: deploy docs by mike
29
+ run: |
30
+ VERSION=$(uv run python scripts/convert_to_pep440_version.py "${{ github.event.release.tag_name }}")
31
+ uv run mike deploy "$VERSION" latest --update-aliases --push
32
+ uv run mike set-default latest --push
@@ -0,0 +1,26 @@
1
+ name: Publish package
2
+
3
+ on:
4
+ release:
5
+ types: ["created"]
6
+
7
+ jobs:
8
+ publish:
9
+ runs-on: ubuntu-latest
10
+ permissions:
11
+ id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+ - uses: actions/setup-python@v5
15
+ with:
16
+ python-version: 3.13
17
+ cache: "pip"
18
+ - run: pip install -r requirements.txt
19
+ - uses: actions/cache@v4
20
+ with:
21
+ path: ~/.cache/uv
22
+ key: uv-3.13-${{ hashFiles('uv.lock') }}
23
+ - run: uv sync --frozen
24
+ - run: uv build
25
+ - name: publish
26
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,41 @@
1
+ name: Test
2
+
3
+ on: ["pull_request", "push"]
4
+
5
+ jobs:
6
+ test:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ matrix:
10
+ python-version: ["3.10", 3.11, 3.12, 3.13]
11
+ steps:
12
+ - uses: actions/checkout@v4
13
+ - uses: actions/setup-python@v5
14
+ with:
15
+ python-version: ${{ matrix.python-version }}
16
+ cache: "pip"
17
+ - run: pip install -r requirements.txt
18
+ - uses: actions/cache@v4
19
+ with:
20
+ path: ~/.cache/uv
21
+ key: uv-${{ matrix.python-version }}-${{ hashFiles('uv.lock') }}
22
+ - run: uv sync --frozen
23
+ - run: uv run pytest
24
+ lint:
25
+ runs-on: ubuntu-latest
26
+ steps:
27
+ - uses: actions/checkout@v4
28
+ - uses: actions/setup-python@v5
29
+ with:
30
+ python-version: 3.13
31
+ cache: pip
32
+ - run: pip install -r requirements.txt
33
+ - uses: actions/cache@v4
34
+ with:
35
+ path: ~/.cache/uv
36
+ key: uv-3.13-${{ hashFiles('uv.lock') }}
37
+ - run: uv sync --frozen
38
+ - run: uv run uv-sort --check
39
+ - run: uv run ruff check --output-format github src/ tests/
40
+ - run: uv run ruff format --check src/ tests/
41
+ - run: uv run mypy src/ tests/
@@ -0,0 +1,179 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+
110
+ # pdm
111
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112
+ #pdm.lock
113
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114
+ # in version control.
115
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
116
+ .pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
121
+ __pypackages__/
122
+
123
+ # Celery stuff
124
+ celerybeat-schedule
125
+ celerybeat.pid
126
+
127
+ # SageMath parsed files
128
+ *.sage.py
129
+
130
+ # Environments
131
+ .env
132
+ .venv
133
+ env/
134
+ venv/
135
+ ENV/
136
+ env.bak/
137
+ venv.bak/
138
+
139
+ # Spyder project settings
140
+ .spyderproject
141
+ .spyproject
142
+
143
+ # Rope project settings
144
+ .ropeproject
145
+
146
+ # mkdocs documentation
147
+ /site
148
+
149
+ # mypy
150
+ .mypy_cache/
151
+ .dmypy.json
152
+ dmypy.json
153
+
154
+ # Pyre type checker
155
+ .pyre/
156
+
157
+ # pytype static type analyzer
158
+ .pytype/
159
+
160
+ # Cython debug symbols
161
+ cython_debug/
162
+
163
+ # PyCharm
164
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
165
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
166
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
167
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
168
+ #.idea/
169
+
170
+ # Ruff stuff:
171
+ .ruff_cache/
172
+
173
+ # PyPI configuration file
174
+ .pypirc
175
+
176
+ # version file
177
+ src/urlscan/_version.py
178
+
179
+ .python-version
@@ -0,0 +1,5 @@
1
+ #!/bin/bash
2
+
3
+ if [ -f ./.venv/bin/activate ]; then
4
+ . ./.venv/bin/activate
5
+ fi
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 urlscan.io
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,98 @@
1
+ Metadata-Version: 2.4
2
+ Name: urlscan-python
3
+ Version: 0.0.1
4
+ Summary: The official Python API client for urlscan.io
5
+ Project-URL: Repository, https://github.com/urlscan/urlscan-python/
6
+ Project-URL: Homepage, https://github.com/urlscan/urlscan-python/
7
+ Project-URL: Documentation, https://urlscan.github.io/urlscan-python/
8
+ Project-URL: Issues, https://github.com/urlscan/urlscan-python/issues/
9
+ License-File: LICENSE
10
+ Classifier: Programming Language :: Python
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Requires-Python: <4.0,>=3.10
16
+ Requires-Dist: httpx~=0.27
17
+ Description-Content-Type: text/markdown
18
+
19
+ # urlscan-python
20
+
21
+ The official Python API client for urlscan.io.
22
+
23
+ ## Requirements
24
+
25
+ - Python 3.10+
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ pip install urlscan-python
31
+ ```
32
+
33
+ ## Quickstart
34
+
35
+ Start by importing `urlscan` module
36
+
37
+ ```py
38
+ >>> import urlscan
39
+ ```
40
+
41
+ Create a client with your API key:
42
+
43
+ ```py
44
+ >>> client = urlscan.Client("<your_api_key>")
45
+ ```
46
+
47
+ Scan a URL:
48
+
49
+ ```py
50
+ >>> res = client.scan("<url>", visibility="public")
51
+ >>> uuid: str = res["uuid"]
52
+ ```
53
+
54
+ Wait for a scan result:
55
+
56
+ ```py
57
+ >>> client.wait_for_result(uuid)
58
+ ```
59
+
60
+ Get a scan result:
61
+
62
+ ```py
63
+ >>> result = client.get_result(uuid)
64
+ ```
65
+
66
+ Bulk scan:
67
+
68
+ ```py
69
+ >>> client.bulk_scan(["<url>", "<url>"], visibility="public")
70
+ ```
71
+
72
+ Alternatively, you can use `_and_get_result(s)` suffixed methods to do scan, wait and get at once.
73
+
74
+ ```py
75
+ >>> client.scan_and_get_result("<url>", visibility="public")
76
+ >>> client.bulk_scan_and_get_results(["<url>", "<url>"], visibility="public")
77
+ ```
78
+
79
+ `urlscan.Client.search()` returns an iterator to iterate search results:
80
+
81
+ ```py
82
+ >>> for result in client.search("page.domain:example.com"):
83
+ >>> print(result["_id"])
84
+ ```
85
+
86
+ ## Examples
87
+
88
+ See [Examples](https://github.com/urlscan/urlscan-python/tree/main/examples/).
89
+
90
+ ## References
91
+
92
+ - [Client](https://urlscan.github.io/urlscan-python/references/client/)
93
+ - [Iterator](https://urlscan.github.io/urlscan-python/references/iterator/)
94
+ - [Errors](https://urlscan.github.io/urlscan-python/references/errors/)
95
+
96
+ ## Help Wanted?
97
+
98
+ Please feel free to to [open an issue](https://github.com/urlscan/urlscan-python/issues/new) if you find a bug or some feature that you want to see implemented.
@@ -0,0 +1,80 @@
1
+ # urlscan-python
2
+
3
+ The official Python API client for urlscan.io.
4
+
5
+ ## Requirements
6
+
7
+ - Python 3.10+
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ pip install urlscan-python
13
+ ```
14
+
15
+ ## Quickstart
16
+
17
+ Start by importing `urlscan` module
18
+
19
+ ```py
20
+ >>> import urlscan
21
+ ```
22
+
23
+ Create a client with your API key:
24
+
25
+ ```py
26
+ >>> client = urlscan.Client("<your_api_key>")
27
+ ```
28
+
29
+ Scan a URL:
30
+
31
+ ```py
32
+ >>> res = client.scan("<url>", visibility="public")
33
+ >>> uuid: str = res["uuid"]
34
+ ```
35
+
36
+ Wait for a scan result:
37
+
38
+ ```py
39
+ >>> client.wait_for_result(uuid)
40
+ ```
41
+
42
+ Get a scan result:
43
+
44
+ ```py
45
+ >>> result = client.get_result(uuid)
46
+ ```
47
+
48
+ Bulk scan:
49
+
50
+ ```py
51
+ >>> client.bulk_scan(["<url>", "<url>"], visibility="public")
52
+ ```
53
+
54
+ Alternatively, you can use `_and_get_result(s)` suffixed methods to do scan, wait and get at once.
55
+
56
+ ```py
57
+ >>> client.scan_and_get_result("<url>", visibility="public")
58
+ >>> client.bulk_scan_and_get_results(["<url>", "<url>"], visibility="public")
59
+ ```
60
+
61
+ `urlscan.Client.search()` returns an iterator to iterate search results:
62
+
63
+ ```py
64
+ >>> for result in client.search("page.domain:example.com"):
65
+ >>> print(result["_id"])
66
+ ```
67
+
68
+ ## Examples
69
+
70
+ See [Examples](https://github.com/urlscan/urlscan-python/tree/main/examples/).
71
+
72
+ ## References
73
+
74
+ - [Client](https://urlscan.github.io/urlscan-python/references/client/)
75
+ - [Iterator](https://urlscan.github.io/urlscan-python/references/iterator/)
76
+ - [Errors](https://urlscan.github.io/urlscan-python/references/errors/)
77
+
78
+ ## Help Wanted?
79
+
80
+ Please feel free to to [open an issue](https://github.com/urlscan/urlscan-python/issues/new) if you find a bug or some feature that you want to see implemented.
@@ -0,0 +1 @@
1
+ {% include-markdown "../README.md" %}
@@ -0,0 +1,42 @@
1
+ # Development
2
+
3
+ This doc explains how to set up dev env if you want to get involved with this project.
4
+
5
+ ## Requirements
6
+
7
+ - Python 3.10+
8
+
9
+ ## Setup
10
+
11
+ This project uses [uv](https://github.com/astral-sh/uv) as a project manager and [Lefthook](https://github.com/evilmartians/lefthook) as a Git hooks manager.
12
+
13
+ ```bash
14
+ git clone https://github.com/urlscan/urlscan-python
15
+ cd urlscan-python
16
+
17
+ # install uv
18
+ pip install -r requirements.txt
19
+ # sync uv
20
+ uv sync
21
+ # install Lefthook
22
+ uv run lefthook install
23
+ ```
24
+
25
+ ## Test
26
+
27
+ This project uses [pytest](https://docs.pytest.org/en/stable/) as a testing framework.
28
+
29
+ ```bash
30
+ uv run pytest
31
+ ```
32
+
33
+ ## Docs
34
+
35
+ This project uses [MkDocs](https://www.mkdocs.org/) as a documentation tool and uses [Mike](https://github.com/jimporter/mike) for versioning.
36
+
37
+ ```bash
38
+ # run the dev server
39
+ uv run mike serve
40
+ # or build the docs
41
+ uv run mke build
42
+ ```
@@ -0,0 +1 @@
1
+ ::: urlscan.Client
@@ -0,0 +1,3 @@
1
+ ::: urlscan.APIError
2
+
3
+ ::: urlscan.RateLimitError
@@ -0,0 +1 @@
1
+ ::: urlscan.SearchIterator
@@ -0,0 +1,45 @@
1
+ # /// script
2
+ # requires-python = ">=3.10"
3
+ # dependencies = [
4
+ # "pillow",
5
+ # "python-dotenv",
6
+ # "typer",
7
+ # "urlscan-python",
8
+ # ]
9
+ # ///
10
+
11
+ # this script demonstrates how to get a screenshot & convert it to a PIL image.
12
+ # usage: uv run examples/screenshot_to_pil.py <UUID>
13
+
14
+ import os
15
+ from typing import Annotated
16
+
17
+ import typer
18
+ from dotenv import load_dotenv
19
+ from PIL import Image
20
+
21
+ import urlscan
22
+
23
+ load_dotenv()
24
+
25
+ API_KEY = os.getenv("URLSCAN_API_KEY")
26
+
27
+
28
+ def main(
29
+ uuid: Annotated[str, typer.Argument(help="Result UUID")],
30
+ api_key: Annotated[
31
+ str | None,
32
+ typer.Option(help="Your API key, defaults to URLSCAN_API_KEY env"),
33
+ ] = None,
34
+ ) -> None:
35
+ api_key = api_key or API_KEY
36
+ assert api_key
37
+
38
+ with urlscan.Client(api_key) as client:
39
+ screenshot = client.get_screenshot(uuid)
40
+ image = Image.open(screenshot)
41
+ image.show()
42
+
43
+
44
+ if __name__ == "__main__":
45
+ typer.run(main)
@@ -0,0 +1,53 @@
1
+ # /// script
2
+ # requires-python = ">=3.10"
3
+ # dependencies = [
4
+ # "python-dotenv",
5
+ # "typer",
6
+ # "urlscan-python",
7
+ # ]
8
+ # ///
9
+
10
+ # this script demonstrates how to do search and download screenshots.
11
+ # usage: uv run examples/search_and_download_screenshots.py <QUERY>
12
+ # (e.g. uv run examples/search_and_download_screenshots.py domain:example.com)
13
+
14
+ import os
15
+ from pathlib import Path
16
+ from typing import Annotated
17
+
18
+ import typer
19
+ from dotenv import load_dotenv
20
+
21
+ import urlscan
22
+
23
+ load_dotenv()
24
+
25
+ API_KEY = os.getenv("URLSCAN_API_KEY")
26
+
27
+
28
+ def main(
29
+ query: Annotated[str, typer.Argument(help="Search query")],
30
+ api_key: Annotated[
31
+ str | None,
32
+ typer.Option(help="Your API key. Defaults to URLSCAN_API_KEY env."),
33
+ ] = None,
34
+ limit: Annotated[int, typer.Option(help="Limit of search results")] = 10,
35
+ dest: Annotated[
36
+ Path, typer.Option(help="Destination directory to download screenshots")
37
+ ] = Path("/tmp"),
38
+ ) -> None:
39
+ api_key = api_key or API_KEY
40
+ assert api_key, "API key is required"
41
+
42
+ with urlscan.Client(api_key) as client:
43
+ for result in client.search(query, limit=limit):
44
+ _id: str = result["_id"]
45
+ screenshot = client.get_screenshot(_id)
46
+
47
+ path = dest / f"{_id}.png"
48
+ path.write_bytes(screenshot.read())
49
+ print(f"Downloaded screenshot to {path}") # noqa: T201
50
+
51
+
52
+ if __name__ == "__main__":
53
+ typer.run(main)
@@ -0,0 +1,58 @@
1
+ # /// script
2
+ # requires-python = ">=3.10"
3
+ # dependencies = [
4
+ # "itables",
5
+ # "pandas",
6
+ # "python-dotenv",
7
+ # "typer",
8
+ # "urlscan-python",
9
+ # ]
10
+ # ///
11
+
12
+ # this script converts search results into a Pandas dataframe & shows it as an HTML table.
13
+ # usage: uv run examples/search_to_dataframe.py <QUERY>
14
+ # (e.g. uv run examples/search_to_dataframe.py domain:example.com)
15
+
16
+ import os
17
+ import webbrowser
18
+ from pathlib import Path
19
+ from typing import Annotated
20
+
21
+ import itables
22
+ import pandas as pd
23
+ import typer
24
+ from dotenv import load_dotenv
25
+
26
+ import urlscan
27
+
28
+ load_dotenv()
29
+
30
+ API_KEY = os.getenv("URLSCAN_API_KEY")
31
+
32
+
33
+ def main(
34
+ query: Annotated[str, typer.Argument(help="Search query")],
35
+ api_key: Annotated[
36
+ str | None,
37
+ typer.Option(help="Your API key, defaults to URLSCAN_API_KEY env"),
38
+ ] = None,
39
+ limit: Annotated[int, typer.Option(help="Limit of search results")] = 100,
40
+ path: Annotated[
41
+ Path, typer.Option(help="Path to save a dataframe as an HTML file")
42
+ ] = Path("report.html"),
43
+ ) -> None:
44
+ api_key = api_key or API_KEY
45
+ assert api_key
46
+
47
+ with urlscan.Client(api_key) as client:
48
+ results = list(client.search(query, limit=limit))
49
+
50
+ df = pd.json_normalize(results)
51
+ html = itables.to_html_datatable(df)
52
+ path.write_text(html)
53
+
54
+ webbrowser.open(path.absolute().as_uri())
55
+
56
+
57
+ if __name__ == "__main__":
58
+ typer.run(main)