pyritrix3 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.
@@ -0,0 +1,218 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
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
+ # poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ # pdm.lock
116
+ # pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ # pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # Redis
135
+ *.rdb
136
+ *.aof
137
+ *.pid
138
+
139
+ # RabbitMQ
140
+ mnesia/
141
+ rabbitmq/
142
+ rabbitmq-data/
143
+
144
+ # ActiveMQ
145
+ activemq-data/
146
+
147
+ # SageMath parsed files
148
+ *.sage.py
149
+
150
+ # Environments
151
+ .env
152
+ .envrc
153
+ .venv
154
+ env/
155
+ venv/
156
+ ENV/
157
+ env.bak/
158
+ venv.bak/
159
+
160
+ # Spyder project settings
161
+ .spyderproject
162
+ .spyproject
163
+
164
+ # Rope project settings
165
+ .ropeproject
166
+
167
+ # mkdocs documentation
168
+ /site
169
+
170
+ # mypy
171
+ .mypy_cache/
172
+ .dmypy.json
173
+ dmypy.json
174
+
175
+ # Pyre type checker
176
+ .pyre/
177
+
178
+ # pytype static type analyzer
179
+ .pytype/
180
+
181
+ # Cython debug symbols
182
+ cython_debug/
183
+
184
+ # PyCharm
185
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
186
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
187
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
188
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
189
+ # .idea/
190
+
191
+ # Abstra
192
+ # Abstra is an AI-powered process automation framework.
193
+ # Ignore directories containing user credentials, local state, and settings.
194
+ # Learn more at https://abstra.io/docs
195
+ .abstra/
196
+
197
+ # Visual Studio Code
198
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
199
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
200
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
201
+ # you could uncomment the following to ignore the entire vscode folder
202
+ # .vscode/
203
+ # Temporary file for partial code execution
204
+ tempCodeRunnerFile.py
205
+
206
+ # Ruff stuff:
207
+ .ruff_cache/
208
+
209
+ # PyPI configuration file
210
+ .pypirc
211
+
212
+ # Marimo
213
+ marimo/_static/
214
+ marimo/_lsp/
215
+ __marimo__/
216
+
217
+ # Streamlit
218
+ .streamlit/secrets.toml
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Emilian Zawrotny
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,16 @@
1
+ Metadata-Version: 2.5
2
+ Name: pyritrix3
3
+ Version: 0.0.1
4
+ Summary: A simple wrapper around Heritrix3' REST API
5
+ Project-URL: Homepage, https://github.com/obrotowy/pyritrix3
6
+ Project-URL: Issues, https://github.com/obrotowy/pyritrix3/issues
7
+ Author-email: Emilian Zawrotny <emilian@zawrotny.pl>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Requires-Python: >=3.9
13
+ Requires-Dist: requests>=2.34.2
14
+ Description-Content-Type: text/markdown
15
+
16
+ Simple wrapper around [Hetririx3](https://github.com/internetarchive/heritrix3) REST API
@@ -0,0 +1 @@
1
+ Simple wrapper around [Hetririx3](https://github.com/internetarchive/heritrix3) REST API
@@ -0,0 +1,24 @@
1
+ [build-system]
2
+ requires = ["hatchling >= 1.26"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "pyritrix3"
7
+ version = "0.0.1"
8
+ authors = [
9
+ { name="Emilian Zawrotny", email="emilian@zawrotny.pl" },
10
+ ]
11
+ description = "A simple wrapper around Heritrix3' REST API"
12
+ readme = "README.md"
13
+ requires-python = ">=3.9"
14
+ dependencies = [ "requests>=2.34.2" ]
15
+ classifiers = [
16
+ "Programming Language :: Python :: 3",
17
+ "Operating System :: OS Independent",
18
+ ]
19
+ license = "MIT"
20
+ license-files = ["LICENSE"]
21
+
22
+ [project.urls]
23
+ Homepage = "https://github.com/obrotowy/pyritrix3"
24
+ Issues = "https://github.com/obrotowy/pyritrix3/issues"
@@ -0,0 +1 @@
1
+ requests
@@ -0,0 +1 @@
1
+ from .pyritrix import pyritrix
@@ -0,0 +1,164 @@
1
+ from typing import TYPE_CHECKING, IO
2
+
3
+ if TYPE_CHECKING:
4
+ from .pyritrix import pyritrix
5
+
6
+
7
+ class JobsEndpoint:
8
+ def __init__(self, client: pyritrix):
9
+ self._client = client
10
+
11
+ def create(self, createpath: str, profile=None) -> dict:
12
+ """
13
+ Creates a new crawl job from the selected profile.
14
+ If no profile is supplied, Defaults (XML) is used.
15
+ Built-in profiles include Defaults (XML) and Defaults (Groovy).
16
+ Existing job profiles may also be selected by passing the profile job’s short name.
17
+ Arguments:
18
+ createpath: the name of the new job
19
+ profile: optional profile name. Existing profiles use their job short names.
20
+ """
21
+ data = {
22
+ "action": "create",
23
+ "createpath": createpath,
24
+ "profile": profile # It's fine, requests will omit this if profile=None
25
+ }
26
+ response = self._client.post("/engine", data=data)
27
+ assert response.status_code == 200
28
+ return response.json()
29
+
30
+ def add(self, addpath: str) -> dict:
31
+ """
32
+ Adds a new job directory to the Heritrix configuration.
33
+ The directory must contain a cxml configuration file.
34
+ Arguments:
35
+ action: must be add
36
+ addpath: the job directory to add
37
+ """
38
+ data = {
39
+ "action": "add",
40
+ "addpath": addpath
41
+ }
42
+ response = self._client.post("/engine", data=data)
43
+ return response.json()
44
+
45
+ def get(self, jobname: str) -> dict:
46
+ """
47
+ Returns status information and statistics about the chosen job.
48
+ """
49
+ return self._client.get(f"/engine/job/{jobname}").json()
50
+
51
+ def build(self, jobname: str) -> dict:
52
+ """
53
+ Builds the job configuration for the chosen job. It reads an XML descriptor file and uses
54
+ Spring to build the Java objects that are necessary for running the crawl.
55
+ Before a crawl can be run it must be built.
56
+ """
57
+ data = {"action": "build"}
58
+ response = self._client.post(f"/engine/job/{jobname}", data=data)
59
+ return response.json()
60
+
61
+ def launch(self, jobname: str, checkpoint: str) -> dict:
62
+ """
63
+ Launches a crawl job. The job can be launched in the “paused” state or the “unpaused” state.
64
+ If launched in the “unpaused” state the job will immediately begin crawling.
65
+ Arguments:
66
+ checkpoint: optional field. If supplied, Heritrix will attempt to launch from a checkpoint.
67
+ Should be the name of a checkpoint (e.g. cp00001-20180102121229) or (since version 3.3)
68
+ the special value latest, which will automatically select the most recent checkpoint.
69
+ If no checkpoint is specified (or if the latest checkpoint is requested and there
70
+ are no valid checkpoints) a new crawl will be launched.
71
+ """
72
+ data = {
73
+ "action": "launch",
74
+ "checkpoint": checkpoint
75
+ }
76
+ response = self._client.post(f"/engine/job/{jobname}", data=data)
77
+ return response.json()
78
+
79
+ def rescan(self) -> dict:
80
+ """
81
+ Rescans the main job directory and returns an HTML page containing all the job names.
82
+ It also returns information about the jobs, such as the location of the job
83
+ configuration file and the number of job launches.
84
+ """
85
+
86
+ return self._client.post("/engine", data={"action": "rescan"}).json()
87
+
88
+ def pause(self, jobname: str) -> dict:
89
+ """
90
+ Pauses an unpaused job. No crawling will occur while a job is paused.
91
+ """
92
+ return self._client.post(f"/engine/job/{jobname}", data={"action": "pause"}).json()
93
+
94
+ def unpause(self, jobname: str) -> dict:
95
+ """
96
+ This API unpauses a paused job. Crawling will resume (or begin, in the case of
97
+ a job launched in the paused state) if possible.
98
+ """
99
+ return self._client.post(f"/engine/job/{jobname}", data={"action": "unpause"}).json()
100
+
101
+ def terminate(self, jobname: str) -> dict:
102
+ """
103
+ Terminates a runnig job.
104
+ """
105
+ return self._client.post(f"/engine/job/{jobname}", data={"action": "terminate"}).json()
106
+
107
+ def teardown(self, jobname: str) -> dict:
108
+ """
109
+ Removes the Spring code that is used to run the job. Once a job is torn down it must be rebuilt in order to run.
110
+ """
111
+ return self._client.post(f"/engine/job/{jobname}", data={"action": "teardown"}).json()
112
+
113
+ def copy(self, jobname: str, copyTo: str, asProfile: bool) -> dict:
114
+ """
115
+ Copies an existing job configuration to a new job configuration. If the asProfile option is submitted with value on,
116
+ then the copy is a non-runnable profile. Profiles are listed as options when creating new jobs,
117
+ and profiles with built-in names override the built-ins.
118
+ Arguments:
119
+ copyTo: the name of the new job or profile configuration
120
+ asProfile: whether to copy the job as a runnable configuration or as a non-runnable profile.
121
+ True means the job will be copied as a profile.
122
+ """
123
+ data = {
124
+ "copyTo": copyTo,
125
+ }
126
+ if asProfile:
127
+ data["asProfile"] = "on"
128
+ return self._client.post(f"/engine/job/{jobname}", data=data).json()
129
+
130
+ def delete(self, jobname: str) -> dict:
131
+ """
132
+ Deletes an existing job. It will remove everything related to the job (configuration, statistics, logs and results)
133
+ including the whole job folder. Everything to keep has to be copied outside of the job folder.
134
+
135
+ Deleting a job is only possible if no active application context for the job exists which is
136
+ the case for new or unbuilt jobs. If a job has been built, it must first be torn down to allow deletion.
137
+ """
138
+ return self._client.post(f"/engine/job/{jobname}", data={"action": "delete"}).json()
139
+
140
+ def checkpoint(self, jobname: str) -> dict:
141
+ """
142
+ This API checkpoints the chosen job. Checkpointing writes the current state of a crawl
143
+ to the file system so that the crawl can be recovered if it fails.
144
+ """
145
+ return self._client.post(f"/engine/job/{jobname}", data={"action": "checkpoint"}).json()
146
+
147
+ def execute_script(self, jobname: str, engine: str, script: str) -> dict:
148
+ """
149
+ Executes a script. The script can be written as Beanshell, ECMAScript, Groovy, or AppleScript.
150
+ Arguments:
151
+ engine: the script engine to use. One of beanshell, js, groovy or AppleScriptEngine.
152
+ script: the script code to execute
153
+ """
154
+ assert script in ["beanshell", "js", "groovy", "AppleScriptEngine"]
155
+ data = {
156
+ "engine": engine,
157
+ "script": script
158
+ }
159
+ return self._client.post(f"/engine/job/{jobname}/script", data=data).json()
160
+
161
+ def submit_config_file(self, jobname: str, file: IO):
162
+ response = self._client.put(
163
+ f"/engine/job/{jobname}/crawler-beans.cxml", data=file)
164
+ assert response.status_code == 200
@@ -0,0 +1,34 @@
1
+ import requests
2
+ from requests.auth import HTTPDigestAuth
3
+ from urllib.parse import urljoin
4
+ from .jobs import JobsEndpoint
5
+
6
+ common_headers = {
7
+ "Accept": "application/json"
8
+ }
9
+
10
+
11
+ class pyritrix():
12
+ def __init__(self, hostname: str, username: str, password: str, port=8443, verify_certs=True):
13
+ self.session = requests.Session()
14
+ self.session.auth = HTTPDigestAuth(username, password)
15
+ self.verify_certs = verify_certs
16
+ self.base_url = f"https://{hostname}:{port}/"
17
+ self.jobs = JobsEndpoint(self)
18
+
19
+ def get(self, path: str, **kwargs) -> requests.Response:
20
+ return self.session.get(
21
+ urljoin(self.base_url, path), headers=common_headers, verify=self.verify_certs, **kwargs)
22
+
23
+ def post(self, path: str, **kwargs) -> requests.Response:
24
+ return self.session.post(
25
+ urljoin(self.base_url, path), headers=common_headers, verify=self.verify_certs, **kwargs)
26
+
27
+ def post(self, path: str, **kwargs) -> requests.Response:
28
+ return self.session.put(urljoin(self.base_url, path), headers=common_headers, verify=self.verify_certs, **kwargs)
29
+
30
+ def status(self) -> dict:
31
+ """
32
+ Returns information about this instance of Heritrix such as version number, memory usage and the list of crawl jobs.
33
+ """
34
+ return self.get("/engine").json()