snapquery 0.2.2__tar.gz → 0.2.4__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.
- snapquery-0.2.4/CITATION.cff +49 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/PKG-INFO +27 -31
- {snapquery-0.2.2 → snapquery-0.2.4}/README.md +22 -26
- {snapquery-0.2.2 → snapquery-0.2.4}/pyproject.toml +5 -4
- snapquery-0.2.4/scripts/test_queries +214 -0
- snapquery-0.2.4/snapquery/__init__.py +1 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/github_access.py +25 -10
- snapquery-0.2.4/snapquery/qlever.py +187 -0
- snapquery-0.2.4/snapquery/query_set_cmd.py +435 -0
- snapquery-0.2.4/snapquery/query_set_tool.py +210 -0
- snapquery-0.2.2/snapquery/qimport_view.py → snapquery-0.2.4/snapquery/query_set_tool_view.py +3 -3
- snapquery-0.2.4/snapquery/samples/query-sets/yaml/ceur-ws.yaml +610 -0
- snapquery-0.2.4/snapquery/samples/query-sets/yaml/dblp.yaml +101 -0
- snapquery-0.2.4/snapquery/samples/query-sets/yaml/federated-query-examples.yaml +291 -0
- snapquery-0.2.4/snapquery/samples/query-sets/yaml/hartig-eqs-2025-12-16.yaml +3033 -0
- snapquery-0.2.4/snapquery/samples/query-sets/yaml/orkg.yaml +40 -0
- snapquery-0.2.4/snapquery/samples/query-sets/yaml/qlever-issues-2025-12-05.yaml +6219 -0
- snapquery-0.2.4/snapquery/samples/query-sets/yaml/qlever.yaml +3724 -0
- snapquery-0.2.4/snapquery/samples/query-sets/yaml/qlever_performance.yaml +100 -0
- snapquery-0.2.4/snapquery/samples/query-sets/yaml/scholia-2025-12-04.yaml +9324 -0
- snapquery-0.2.4/snapquery/samples/query-sets/yaml/scholia-2025-12-16.yaml +9324 -0
- snapquery-0.2.4/snapquery/samples/query-sets/yaml/scholia-qlever-2025-12-16.yaml +14907 -0
- snapquery-0.2.4/snapquery/samples/query-sets/yaml/scholia.yaml +8952 -0
- snapquery-0.2.4/snapquery/samples/query-sets/yaml/sib-2025-12-04.yaml +24822 -0
- snapquery-0.2.4/snapquery/samples/query-sets/yaml/snapquery.yaml +26 -0
- snapquery-0.2.4/snapquery/samples/query-sets/yaml/wikidata-WikidataThesisToolkit.yaml +422 -0
- snapquery-0.2.4/snapquery/samples/query-sets/yaml/wikidata-WikidataThesisToolkitAlt.yaml +472 -0
- snapquery-0.2.4/snapquery/samples/query-sets/yaml/wikidata-examples-2025-12-04.yaml +8715 -0
- snapquery-0.2.4/snapquery/samples/query-sets/yaml/wikidata-examples.yaml +6751 -0
- snapquery-0.2.4/snapquery/samples/query-sets/yaml/wikidata-short-urls-2025-12-06.yaml +1541 -0
- snapquery-0.2.4/snapquery/samples/query-sets/yaml/wikidata-short-urls.yaml +1868 -0
- snapquery-0.2.4/snapquery/scholia.py +161 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/sib_sparql_examples.py +13 -7
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/snapquery_cmd.py +13 -5
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/snapquery_webserver.py +11 -5
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/sparql_analyzer.py +1 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/version.py +1 -1
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/wd_page_query_extractor.py +41 -15
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/wd_short_url.py +13 -10
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery.puml +3 -1
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/test_endpoints.py +3 -3
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/test_qlever.py +18 -36
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/test_query_name.py +2 -2
- snapquery-0.2.4/tests/test_query_set_tool.py +153 -0
- snapquery-0.2.4/tests/test_scholia.py +246 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/test_sib_examples.py +10 -6
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/test_sparql_analyzer.py +1 -1
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/test_wd_query_parsing.py +3 -3
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/test_wd_short_url.py +4 -1
- snapquery-0.2.2/scripts/test_queries +0 -75
- snapquery-0.2.2/snapquery/__init__.py +0 -1
- snapquery-0.2.2/snapquery/qimport.py +0 -117
- snapquery-0.2.2/snapquery/qlever.py +0 -111
- snapquery-0.2.2/snapquery/scholia.py +0 -107
- snapquery-0.2.2/tests/test_import.py +0 -86
- snapquery-0.2.2/tests/test_scholia.py +0 -57
- {snapquery-0.2.2 → snapquery-0.2.4}/.github/workflows/build.yml +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/.github/workflows/upload-to-pypi.yml +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/.gitignore +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/.project +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/.pydevproject +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/LICENSE +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/docs/index.md +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/mkdocs.yml +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/scripts/blackisort +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/scripts/doc +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/scripts/fixdomain +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/scripts/install +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/scripts/qlv +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/scripts/release +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/scripts/restore_db +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/scripts/test +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/authorization.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/basequeryview.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/ceurws.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/dblp.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/error_filter.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/execution.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/graph.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/models/__init__.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/models/person.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/models/sparql_components.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/mwlogin.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/namespace_stats_view.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/orcid.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/params_view.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/person_selector.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/pid.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/pid_lookup.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/prefix_merger.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/query_annotate.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/query_selector.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/resources/sparql_language.json +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/samples/WikiProject_LSEThesisProject.wiki +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/samples/ceur-ws.json +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/samples/dblp.json +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/samples/endpoints.yaml +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/samples/endpoints_optional.yaml +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/samples/federated-query-examples.json +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/samples/graphs.yaml +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/samples/meta_query.yaml +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/samples/orkg.json +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/samples/qlever.json +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/samples/qlever_performance.json +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/samples/query_stats.yaml +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/samples/scholia.json +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/samples/snapquery.json +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/samples/wikidata-WikidataThesisToolkit.json +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/samples/wikidata-WikidataThesisToolkitAlt.json +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/samples/wikidata-examples.json +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/samples/wikidata-short-urls.json +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/snapquery_core.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/snapquery_view.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery/stats_view.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/snapquery.yaml +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/__init__.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/action_stats.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/query_extractors/__init__.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/query_extractors/sparql_standard_queries.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/resources/error_messages/qlever/ask_unsupported.txt +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/resources/error_messages/qlever/invalid_literal.txt +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/resources/error_messages/qlever/invalid_regex_func.txt +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/resources/error_messages/qlever/memory_limit.txt +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/resources/error_messages/qlever/timeout.txt +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/resources/error_messages/triplydb/parser_error.txt +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/resources/error_messages/wdqs/duplicate_prefix.txt +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/resources/error_messages/wdqs/invalid_iri_declaration.txt +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/resources/error_messages/wdqs/invalid_sparql_syntax.txt +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/resources/error_messages/wdqs/timeout.txt +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/resources/error_messages/wdqs/undefined_prefix.txt +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/test_authorization.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/test_ceurws.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/test_cmdline.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/test_error_filter.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/test_graph.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/test_namedqueries.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/test_oauth.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/test_orcid.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/test_pids.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/test_prefix_merger.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/test_query_annotate.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/test_query_execution.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/test_restful_api.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/test_scholia_q.py +0 -0
- {snapquery-0.2.2 → snapquery-0.2.4}/tests/test_sparql_components.py +0 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# CITATION.cff for https://github.com/WolfgangFahl/snapquery
|
|
2
|
+
# This CITATION.cff file was initially generated with cffinit.
|
|
3
|
+
# Visit https://bit.ly/cffinit to generate yours today!
|
|
4
|
+
cff-version: 1.2.0
|
|
5
|
+
title: SnapQuery
|
|
6
|
+
message: >-
|
|
7
|
+
If you use this software, please cite it using the
|
|
8
|
+
metadata from this file.
|
|
9
|
+
type: software
|
|
10
|
+
authors:
|
|
11
|
+
- given-names: Wolfgang
|
|
12
|
+
family-names: Fahl
|
|
13
|
+
affiliation: BITPlan GmbH
|
|
14
|
+
orcid: 'https://orcid.org/0000-0002-0821-6995'
|
|
15
|
+
- given-names: Tim
|
|
16
|
+
family-names: Holzheim
|
|
17
|
+
orcid: 'https://orcid.org/0000-0003-2533-6363'
|
|
18
|
+
- given-names: "Charles Tapley"
|
|
19
|
+
family-names: Hoyt
|
|
20
|
+
orcid: 'https://orcid.org/0000-0003-4423-4370'
|
|
21
|
+
- given-names: Dennis
|
|
22
|
+
family-names: Priskorn
|
|
23
|
+
orcid: 'https://orcid.org/0000-0002-7669-8498'
|
|
24
|
+
- given-names: Egon
|
|
25
|
+
family-names: Willighagen
|
|
26
|
+
orcid: 'https://orcid.org/0000-0001-7542-0286'
|
|
27
|
+
# - given-names: Wouter
|
|
28
|
+
# family-names: Beek
|
|
29
|
+
# orcid: 'https://orcid.org/0000-0003-0250-9655'
|
|
30
|
+
identifiers:
|
|
31
|
+
- type: doi
|
|
32
|
+
value: 10.5281/zenodo.17802425
|
|
33
|
+
repository-code: 'https://github.com/WolfgangFahl/snapquery'
|
|
34
|
+
url: 'https://snapquery.bitplan.com'
|
|
35
|
+
abstract: >-
|
|
36
|
+
FAIR Management of Query Sets to Mitigate Query Rot in
|
|
37
|
+
Knowledge Graphs
|
|
38
|
+
keywords:
|
|
39
|
+
- SPARQL
|
|
40
|
+
- Query Rot
|
|
41
|
+
- Knowledge Graph Management
|
|
42
|
+
- Benchmarking
|
|
43
|
+
- Refactoring
|
|
44
|
+
- Middleware
|
|
45
|
+
- Query Set
|
|
46
|
+
- FAIR
|
|
47
|
+
license: Apache-2.0
|
|
48
|
+
version: v0.2.2
|
|
49
|
+
date-released: '2025-12-03'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: snapquery
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: Just Query wikidata and other SPARQL endpoints by query name - a frontend to Introduce Named Queries and Named Query Middleware to wikidata and other SPARQL endpoints
|
|
5
5
|
Project-URL: Home, https://github.com/WolfgangFahl/snapquery
|
|
6
6
|
Project-URL: Documentation, https://wiki.bitplan.com/index.php/snapquery
|
|
@@ -26,14 +26,14 @@ Classifier: Topic :: Software Development :: User Interfaces
|
|
|
26
26
|
Requires-Python: >=3.10
|
|
27
27
|
Requires-Dist: mwoauth>=0.4.0
|
|
28
28
|
Requires-Dist: nameparser>=1.1.3
|
|
29
|
-
Requires-Dist: ngwidgets>=0.30.
|
|
29
|
+
Requires-Dist: ngwidgets>=0.30.3
|
|
30
30
|
Requires-Dist: nicegui[plotly]==2.24.2
|
|
31
31
|
Requires-Dist: pandas>=2.3.3
|
|
32
32
|
Requires-Dist: py-3rdparty-mediawiki>=0.18.1
|
|
33
33
|
Requires-Dist: py-ez-wikidata>=0.3.2
|
|
34
|
-
Requires-Dist: pybasemkit>=0.1.
|
|
35
|
-
Requires-Dist: pylodstorage>=0.18.
|
|
36
|
-
Requires-Dist: pyopensourceprojects>=0.
|
|
34
|
+
Requires-Dist: pybasemkit>=0.1.6
|
|
35
|
+
Requires-Dist: pylodstorage>=0.18.6
|
|
36
|
+
Requires-Dist: pyopensourceprojects>=0.4.1
|
|
37
37
|
Requires-Dist: python-slugify>=8.0.4
|
|
38
38
|
Requires-Dist: ratelimit>=2.2.1
|
|
39
39
|
Requires-Dist: requests
|
|
@@ -44,26 +44,30 @@ Requires-Dist: green; extra == 'test'
|
|
|
44
44
|
Description-Content-Type: text/markdown
|
|
45
45
|
|
|
46
46
|
# snapQuery
|
|
47
|
-
Just query
|
|
47
|
+
Just query by name of query ...
|
|
48
48
|
<pre>snapquery cats</pre> is all you need
|
|
49
49
|
|
|
50
|
-
This endpoint and query detail independent style of querying wikidata and
|
|
51
|
-
makes your queries future proof. No worries about blazegraph being replaced, the graph being split or timeouts haunting you.
|
|
50
|
+
This endpoint and query detail independent style of querying wikidata and similar knowledge graph services
|
|
51
|
+
makes your queries future proof. No worries about blazegraph being replaced, the graph being split or timeouts haunting you.
|
|
52
|
+
snapquery introduces named queries and named query middleware to wikidata and other knowledge graph endpoints.
|
|
52
53
|
|
|
53
|
-
snapquery is a tool that simplifies the process of previewing, annotating, rating, commenting, running, and exploring
|
|
54
|
-
queries across different
|
|
54
|
+
snapquery is a tool that simplifies the process of previewing, annotating, rating, commenting, running, and exploring
|
|
55
|
+
queries across different backends. It enhances user experience by storing query results and allowing easy
|
|
55
56
|
comparison across various backends and over time.
|
|
56
57
|
|
|
57
58
|
This tool is designed to assist users in curating and collaborating on queries, ensuring their continued functionality
|
|
58
59
|
over time. Developers and data consumers can access data conveniently through APIs, streamlining their workflow.
|
|
59
60
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
| **PyPi** | [](https://pypi.python.org/pypi/snapquery/) [](https://www.apache.org/licenses/LICENSE-2.0) [](https://pypi.org/project/snapquery/) [](https://pypi.org/project/snapquery/) [](https://pypi.org/project/snapquery/) |
|
|
63
|
-
| **GitHub** | [](https://github.com/WolfgangFahl/snapquery/actions/workflows/build.yml) [](https://github.com/WolfgangFahl/snapquery/releases) [](https://github.com/WolfgangFahl/snapquery/graphs/contributors) [](https://github.com/WolfgangFahl/snapquery/commits/) [](https://github.com/WolfgangFahl/snapquery/issues) [](https://github.com/WolfgangFahl/snapquery/issues/?q=is%3Aissue+is%3Aclosed) |
|
|
64
|
-
| **Code** | [](https://github.com/psf/black) [](https://pycqa.github.io/isort/) |
|
|
65
|
-
| **Docs** | [](https://WolfgangFahl.github.io/snapquery/) [](https://github.com/PyCQA/docformatter) [](https://google.github.io/styleguide/pyguide.html#s3.8-comments-and-docstrings) |
|
|
61
|
+
The technology behind the backend knowlede graphs such as RDF, SPARQL, SQL, CSV, APIs is hidden.
|
|
62
|
+
|
|
66
63
|
|
|
64
|
+
| | |
|
|
65
|
+
| :--- | :--- |
|
|
66
|
+
| **PyPi** | [](https://pypi.python.org/pypi/snapquery/) [](https://www.apache.org/licenses/LICENSE-2.0) [](https://pypi.org/project/snapquery/) [](https://pypi.org/project/snapquery/) [](https://pypi.org/project/snapquery/) |
|
|
67
|
+
| **GitHub** | [](https://github.com/WolfgangFahl/snapquery/actions/workflows/build.yml) [](https://github.com/WolfgangFahl/snapquery/releases) [](https://github.com/WolfgangFahl/snapquery/graphs/contributors) [](https://github.com/WolfgangFahl/snapquery/commits/) [](https://github.com/WolfgangFahl/snapquery/issues) [](https://github.com/WolfgangFahl/snapquery/issues/?q=is%3Aissue+is%3Aclosed) |
|
|
68
|
+
| **Code** | [](https://github.com/psf/black) [](https://pycqa.github.io/isort/) |
|
|
69
|
+
| **Docs** | [](https://WolfgangFahl.github.io/snapquery/) [](https://github.com/PyCQA/docformatter) [](https://google.github.io/styleguide/pyguide.html#s3.8-comments-and-docstrings) |
|
|
70
|
+
[](https://doi.org/10.5281/zenodo.17802424)
|
|
67
71
|
[](https://github.com/WolfgangFahl/snapquery/discussions)
|
|
68
72
|
## Demos
|
|
69
73
|
|
|
@@ -121,25 +125,25 @@ These are the planned features
|
|
|
121
125
|
|
|
122
126
|
* support for naming queries ([#9][i9]) ✅
|
|
123
127
|
* support for sharing queries (unique identifier) ([#2][i2]) ✅
|
|
124
|
-
* query multiple backends simultaneously and repeatedly
|
|
125
|
-
* stores queries and adaptations needed for different backends
|
|
126
|
-
* support user login
|
|
128
|
+
* query multiple backends simultaneously and repeatedly ✅
|
|
129
|
+
* stores queries and adaptations needed for different backends ✅
|
|
130
|
+
* support user login ✅
|
|
127
131
|
* support for spam protection
|
|
128
132
|
* support for rating queries
|
|
129
133
|
* support for commenting on queries
|
|
130
|
-
* support for detecting when a query returns different results between different backends
|
|
131
|
-
* support for query states: reliable, needs investigation, need verification
|
|
134
|
+
* support for detecting when a query returns different results between different backends ✅
|
|
135
|
+
* support for query states: reliable, needs investigation, need verification ✅
|
|
132
136
|
* support for autodetecting when a query returns fewer results than before (change in underlying data/model in
|
|
133
137
|
Wikidata) -> needs investigation
|
|
134
138
|
* support for marking queries as reliable query by users
|
|
135
|
-
* support for seeing a state history per query
|
|
139
|
+
* support for seeing a state history per query ✅
|
|
136
140
|
* support for storing query results so you don’t have to wait
|
|
137
141
|
* support for adding metadata to queries
|
|
138
142
|
* add main subject (QID) to query
|
|
139
143
|
* author -> id of author in the system
|
|
140
144
|
* forked from x
|
|
141
145
|
* has REST API for data consumers e.g. LLM developers who want to present user-verified queries and data to users to
|
|
142
|
-
increase reliability
|
|
146
|
+
increase reliability ✅
|
|
143
147
|
|
|
144
148
|
## User stories
|
|
145
149
|
|
|
@@ -193,19 +197,11 @@ These are the planned features
|
|
|
193
197
|
|
|
194
198
|
[i10]: https://github.com/WolfgangFahl/snapquery/issues/10
|
|
195
199
|
[i9]: https://github.com/WolfgangFahl/snapquery/issues/9
|
|
196
|
-
|
|
197
200
|
[i8]: https://github.com/WolfgangFahl/snapquery/issues/8
|
|
198
|
-
|
|
199
201
|
[i7]: https://github.com/WolfgangFahl/snapquery/issues/7
|
|
200
|
-
|
|
201
202
|
[i6]: https://github.com/WolfgangFahl/snapquery/issues/6
|
|
202
|
-
|
|
203
203
|
[i5]: https://github.com/WolfgangFahl/snapquery/issues/5
|
|
204
|
-
|
|
205
204
|
[i4]: https://github.com/WolfgangFahl/snapquery/issues/4
|
|
206
|
-
|
|
207
205
|
[i3]: https://github.com/WolfgangFahl/snapquery/issues/3
|
|
208
|
-
|
|
209
206
|
[i2]: https://github.com/WolfgangFahl/snapquery/issues/2
|
|
210
|
-
|
|
211
207
|
[i1]: https://github.com/WolfgangFahl/snapquery/issues/1
|
|
@@ -1,24 +1,28 @@
|
|
|
1
1
|
# snapQuery
|
|
2
|
-
Just query
|
|
2
|
+
Just query by name of query ...
|
|
3
3
|
<pre>snapquery cats</pre> is all you need
|
|
4
4
|
|
|
5
|
-
This endpoint and query detail independent style of querying wikidata and
|
|
6
|
-
makes your queries future proof. No worries about blazegraph being replaced, the graph being split or timeouts haunting you.
|
|
5
|
+
This endpoint and query detail independent style of querying wikidata and similar knowledge graph services
|
|
6
|
+
makes your queries future proof. No worries about blazegraph being replaced, the graph being split or timeouts haunting you.
|
|
7
|
+
snapquery introduces named queries and named query middleware to wikidata and other knowledge graph endpoints.
|
|
7
8
|
|
|
8
|
-
snapquery is a tool that simplifies the process of previewing, annotating, rating, commenting, running, and exploring
|
|
9
|
-
queries across different
|
|
9
|
+
snapquery is a tool that simplifies the process of previewing, annotating, rating, commenting, running, and exploring
|
|
10
|
+
queries across different backends. It enhances user experience by storing query results and allowing easy
|
|
10
11
|
comparison across various backends and over time.
|
|
11
12
|
|
|
12
13
|
This tool is designed to assist users in curating and collaborating on queries, ensuring their continued functionality
|
|
13
14
|
over time. Developers and data consumers can access data conveniently through APIs, streamlining their workflow.
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
| **PyPi** | [](https://pypi.python.org/pypi/snapquery/) [](https://www.apache.org/licenses/LICENSE-2.0) [](https://pypi.org/project/snapquery/) [](https://pypi.org/project/snapquery/) [](https://pypi.org/project/snapquery/) |
|
|
18
|
-
| **GitHub** | [](https://github.com/WolfgangFahl/snapquery/actions/workflows/build.yml) [](https://github.com/WolfgangFahl/snapquery/releases) [](https://github.com/WolfgangFahl/snapquery/graphs/contributors) [](https://github.com/WolfgangFahl/snapquery/commits/) [](https://github.com/WolfgangFahl/snapquery/issues) [](https://github.com/WolfgangFahl/snapquery/issues/?q=is%3Aissue+is%3Aclosed) |
|
|
19
|
-
| **Code** | [](https://github.com/psf/black) [](https://pycqa.github.io/isort/) |
|
|
20
|
-
| **Docs** | [](https://WolfgangFahl.github.io/snapquery/) [](https://github.com/PyCQA/docformatter) [](https://google.github.io/styleguide/pyguide.html#s3.8-comments-and-docstrings) |
|
|
16
|
+
The technology behind the backend knowlede graphs such as RDF, SPARQL, SQL, CSV, APIs is hidden.
|
|
17
|
+
|
|
21
18
|
|
|
19
|
+
| | |
|
|
20
|
+
| :--- | :--- |
|
|
21
|
+
| **PyPi** | [](https://pypi.python.org/pypi/snapquery/) [](https://www.apache.org/licenses/LICENSE-2.0) [](https://pypi.org/project/snapquery/) [](https://pypi.org/project/snapquery/) [](https://pypi.org/project/snapquery/) |
|
|
22
|
+
| **GitHub** | [](https://github.com/WolfgangFahl/snapquery/actions/workflows/build.yml) [](https://github.com/WolfgangFahl/snapquery/releases) [](https://github.com/WolfgangFahl/snapquery/graphs/contributors) [](https://github.com/WolfgangFahl/snapquery/commits/) [](https://github.com/WolfgangFahl/snapquery/issues) [](https://github.com/WolfgangFahl/snapquery/issues/?q=is%3Aissue+is%3Aclosed) |
|
|
23
|
+
| **Code** | [](https://github.com/psf/black) [](https://pycqa.github.io/isort/) |
|
|
24
|
+
| **Docs** | [](https://WolfgangFahl.github.io/snapquery/) [](https://github.com/PyCQA/docformatter) [](https://google.github.io/styleguide/pyguide.html#s3.8-comments-and-docstrings) |
|
|
25
|
+
[](https://doi.org/10.5281/zenodo.17802424)
|
|
22
26
|
[](https://github.com/WolfgangFahl/snapquery/discussions)
|
|
23
27
|
## Demos
|
|
24
28
|
|
|
@@ -76,25 +80,25 @@ These are the planned features
|
|
|
76
80
|
|
|
77
81
|
* support for naming queries ([#9][i9]) ✅
|
|
78
82
|
* support for sharing queries (unique identifier) ([#2][i2]) ✅
|
|
79
|
-
* query multiple backends simultaneously and repeatedly
|
|
80
|
-
* stores queries and adaptations needed for different backends
|
|
81
|
-
* support user login
|
|
83
|
+
* query multiple backends simultaneously and repeatedly ✅
|
|
84
|
+
* stores queries and adaptations needed for different backends ✅
|
|
85
|
+
* support user login ✅
|
|
82
86
|
* support for spam protection
|
|
83
87
|
* support for rating queries
|
|
84
88
|
* support for commenting on queries
|
|
85
|
-
* support for detecting when a query returns different results between different backends
|
|
86
|
-
* support for query states: reliable, needs investigation, need verification
|
|
89
|
+
* support for detecting when a query returns different results between different backends ✅
|
|
90
|
+
* support for query states: reliable, needs investigation, need verification ✅
|
|
87
91
|
* support for autodetecting when a query returns fewer results than before (change in underlying data/model in
|
|
88
92
|
Wikidata) -> needs investigation
|
|
89
93
|
* support for marking queries as reliable query by users
|
|
90
|
-
* support for seeing a state history per query
|
|
94
|
+
* support for seeing a state history per query ✅
|
|
91
95
|
* support for storing query results so you don’t have to wait
|
|
92
96
|
* support for adding metadata to queries
|
|
93
97
|
* add main subject (QID) to query
|
|
94
98
|
* author -> id of author in the system
|
|
95
99
|
* forked from x
|
|
96
100
|
* has REST API for data consumers e.g. LLM developers who want to present user-verified queries and data to users to
|
|
97
|
-
increase reliability
|
|
101
|
+
increase reliability ✅
|
|
98
102
|
|
|
99
103
|
## User stories
|
|
100
104
|
|
|
@@ -148,19 +152,11 @@ These are the planned features
|
|
|
148
152
|
|
|
149
153
|
[i10]: https://github.com/WolfgangFahl/snapquery/issues/10
|
|
150
154
|
[i9]: https://github.com/WolfgangFahl/snapquery/issues/9
|
|
151
|
-
|
|
152
155
|
[i8]: https://github.com/WolfgangFahl/snapquery/issues/8
|
|
153
|
-
|
|
154
156
|
[i7]: https://github.com/WolfgangFahl/snapquery/issues/7
|
|
155
|
-
|
|
156
157
|
[i6]: https://github.com/WolfgangFahl/snapquery/issues/6
|
|
157
|
-
|
|
158
158
|
[i5]: https://github.com/WolfgangFahl/snapquery/issues/5
|
|
159
|
-
|
|
160
159
|
[i4]: https://github.com/WolfgangFahl/snapquery/issues/4
|
|
161
|
-
|
|
162
160
|
[i3]: https://github.com/WolfgangFahl/snapquery/issues/3
|
|
163
|
-
|
|
164
161
|
[i2]: https://github.com/WolfgangFahl/snapquery/issues/2
|
|
165
|
-
|
|
166
162
|
[i1]: https://github.com/WolfgangFahl/snapquery/issues/1
|
|
@@ -22,11 +22,11 @@ dependencies = [
|
|
|
22
22
|
# https://pypi.org/project/pybasemkit/
|
|
23
23
|
# https://github.com/WolfgangFahl/pybasemkit
|
|
24
24
|
# Python base module kit: YAML/JSON I/O, structured logging, CLI tooling, shell execution, and remote pydevd debug support.
|
|
25
|
-
"pybasemkit>=0.1.
|
|
25
|
+
"pybasemkit>=0.1.6",
|
|
26
26
|
# https://github.com/WolfgangFahl/nicegui_widgets
|
|
27
|
-
"ngwidgets>=0.30.
|
|
27
|
+
"ngwidgets>=0.30.3",
|
|
28
28
|
# https://pypi.org/project/pyLodStorage/
|
|
29
|
-
"pyLodStorage>=0.18.
|
|
29
|
+
"pyLodStorage>=0.18.6",
|
|
30
30
|
# https://pypi.org/project/py-3rdparty-mediawiki/
|
|
31
31
|
"py-3rdparty-mediawiki>=0.18.1",
|
|
32
32
|
"wikitextparser",
|
|
@@ -51,7 +51,7 @@ dependencies = [
|
|
|
51
51
|
# https://pypi.org/project/nameparser/
|
|
52
52
|
"nameparser>=1.1.3",
|
|
53
53
|
# https://github.com/WolfgangFahl/pyOpenSourceProjects
|
|
54
|
-
"pyOpenSourceProjects>=0.
|
|
54
|
+
"pyOpenSourceProjects>=0.4.1"
|
|
55
55
|
]
|
|
56
56
|
|
|
57
57
|
requires-python = ">=3.10"
|
|
@@ -95,6 +95,7 @@ only-include = ["snapquery"]
|
|
|
95
95
|
|
|
96
96
|
[project.scripts]
|
|
97
97
|
snapquery = "snapquery.snapquery_cmd:main"
|
|
98
|
+
query-set = "snapquery.query_set_cmd:main"
|
|
98
99
|
|
|
99
100
|
[tool.black]
|
|
100
101
|
line-length = 120
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# WF 2024-06-05
|
|
3
|
+
# Enhanced script to handle snapquery calls efficiently and with feedback
|
|
4
|
+
|
|
5
|
+
# Function to execute snapquery in the background with feedback
|
|
6
|
+
run_snapquery() {
|
|
7
|
+
local domain="$1"
|
|
8
|
+
local namespace="$2"
|
|
9
|
+
local endpoint="$3"
|
|
10
|
+
# Sanitize the namespace to be filesystem-friendly
|
|
11
|
+
local sanitized_namespace="${namespace//\//-}" # Replace slashes with hyphens
|
|
12
|
+
sanitized_namespace="${sanitized_namespace//[^a-zA-Z0-9-_]/_}" # Replace any non-alphanumeric characters with underscores
|
|
13
|
+
# Ensure the log directory exists
|
|
14
|
+
local log_dir="/tmp/query_test_log"
|
|
15
|
+
mkdir -p "$log_dir"
|
|
16
|
+
local log="${log_dir}/${endpoint}-${sanitized_namespace}@${domain}.log"
|
|
17
|
+
local command="snapquery -d -tq --progress -en '$endpoint' --context 'cmd_line_tests' --domain '$domain' --namespace '$namespace'"
|
|
18
|
+
echo "Running $command..."
|
|
19
|
+
nohup bash -c "$command" 2>&1 > "$log" &
|
|
20
|
+
echo "... logged at $log"
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
# Function to determine which endpoints to use based on the domain
|
|
24
|
+
select_endpoints() {
|
|
25
|
+
local domain="$1"
|
|
26
|
+
local namespace="$2"
|
|
27
|
+
|
|
28
|
+
case "$domain" in
|
|
29
|
+
dblp.org)
|
|
30
|
+
echo "dblp"
|
|
31
|
+
;;
|
|
32
|
+
orkg.org)
|
|
33
|
+
echo "wikidata" # ORKG data might work with Wikidata endpoints
|
|
34
|
+
;;
|
|
35
|
+
wikidata.org)
|
|
36
|
+
echo "wikidata wikidata-main wikidata-scholarly wikidata-dbis wikidata-qlever"
|
|
37
|
+
;;
|
|
38
|
+
ceur-ws.org)
|
|
39
|
+
echo "wikidata" # CEUR-WS queries likely target Wikidata
|
|
40
|
+
;;
|
|
41
|
+
scholia.toolforge.org)
|
|
42
|
+
echo "wikidata wikidata-scholarly" # Scholia is Wikidata-focused
|
|
43
|
+
;;
|
|
44
|
+
bitplan.com)
|
|
45
|
+
echo "wikidata wikidata-qlever"
|
|
46
|
+
;;
|
|
47
|
+
qlever.cs.uni-freiburg.de)
|
|
48
|
+
case "$namespace" in
|
|
49
|
+
performance-dblp)
|
|
50
|
+
echo "dblp"
|
|
51
|
+
;;
|
|
52
|
+
issues.wikidata)
|
|
53
|
+
echo "wikidata-qlever wikidata-qlever-dbis"
|
|
54
|
+
;;
|
|
55
|
+
*)
|
|
56
|
+
echo "wikidata-qlever wikidata-qlever-dbis"
|
|
57
|
+
;;
|
|
58
|
+
esac
|
|
59
|
+
;;
|
|
60
|
+
genealogy.net)
|
|
61
|
+
echo "gov"
|
|
62
|
+
;;
|
|
63
|
+
*)
|
|
64
|
+
# Default fallback - use basic Wikidata endpoints
|
|
65
|
+
echo "wikidata"
|
|
66
|
+
;;
|
|
67
|
+
esac
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
# Function to loop over selected endpoints and execute queries
|
|
71
|
+
execute_queries() {
|
|
72
|
+
local domain="$1"
|
|
73
|
+
local namespace="$2"
|
|
74
|
+
local endpoints=$(select_endpoints "$domain" "$namespace")
|
|
75
|
+
IFS=' ' read -ra endpoint_array <<< "$endpoints"
|
|
76
|
+
for endpoint in "${endpoint_array[@]}"; do
|
|
77
|
+
run_snapquery "$domain" "$namespace" "$endpoint"
|
|
78
|
+
done
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
# Function to check if an endpoint is available
|
|
82
|
+
check_endpoint() {
|
|
83
|
+
local endpoint="$1"
|
|
84
|
+
local available_endpoints=$(snapquery -le | cut -d':' -f1)
|
|
85
|
+
if echo "$available_endpoints" | grep -q "^$endpoint$"; then
|
|
86
|
+
return 0
|
|
87
|
+
else
|
|
88
|
+
return 1
|
|
89
|
+
fi
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
# Function to filter available endpoints
|
|
93
|
+
filter_available_endpoints() {
|
|
94
|
+
local endpoints="$1"
|
|
95
|
+
local available=""
|
|
96
|
+
IFS=' ' read -ra endpoint_array <<< "$endpoints"
|
|
97
|
+
for endpoint in "${endpoint_array[@]}"; do
|
|
98
|
+
if check_endpoint "$endpoint"; then
|
|
99
|
+
available="$available $endpoint"
|
|
100
|
+
else
|
|
101
|
+
echo "Warning: Endpoint '$endpoint' not available, skipping..."
|
|
102
|
+
fi
|
|
103
|
+
done
|
|
104
|
+
echo "$available" | sed 's/^ *//' # Remove leading space
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
# Enhanced execute_queries function with endpoint validation
|
|
108
|
+
execute_queries_safe() {
|
|
109
|
+
local domain="$1"
|
|
110
|
+
local namespace="$2"
|
|
111
|
+
local selected_endpoints=$(select_endpoints "$domain" "$namespace")
|
|
112
|
+
local available_endpoints=$(filter_available_endpoints "$selected_endpoints")
|
|
113
|
+
|
|
114
|
+
if [ -z "$available_endpoints" ]; then
|
|
115
|
+
echo "No available endpoints for $domain/$namespace"
|
|
116
|
+
return 1
|
|
117
|
+
fi
|
|
118
|
+
|
|
119
|
+
IFS=' ' read -ra endpoint_array <<< "$available_endpoints"
|
|
120
|
+
for endpoint in "${endpoint_array[@]}"; do
|
|
121
|
+
run_snapquery "$domain" "$namespace" "$endpoint"
|
|
122
|
+
done
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
# Main function to process namespace data
|
|
126
|
+
process_namespace_data() {
|
|
127
|
+
local namespace_data=$(snapquery -ln) # Fetch namespaces and their totals dynamically
|
|
128
|
+
|
|
129
|
+
while IFS=':' read -r full_namespace count; do
|
|
130
|
+
local namespace="${full_namespace%%@*}"
|
|
131
|
+
local domain="${full_namespace#*@}"
|
|
132
|
+
echo "Processing $domain/$namespace with total entries $count"
|
|
133
|
+
execute_queries_safe "$domain" "$namespace"
|
|
134
|
+
done <<< "$namespace_data"
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
# Function to show available endpoints
|
|
138
|
+
show_available_endpoints() {
|
|
139
|
+
echo "Available endpoints:"
|
|
140
|
+
snapquery -le | while IFS=':' read -r name url sparql_url method; do
|
|
141
|
+
echo " $name: $url -> $sparql_url ($method)"
|
|
142
|
+
done
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
# Function to show usage
|
|
146
|
+
show_usage() {
|
|
147
|
+
cat << EOF
|
|
148
|
+
Usage: $0 [OPTIONS]
|
|
149
|
+
|
|
150
|
+
Options:
|
|
151
|
+
-h, --help Show this help message
|
|
152
|
+
-e, --endpoints Show available endpoints
|
|
153
|
+
-d, --dry-run Show what would be executed without running
|
|
154
|
+
-n, --namespace NS Process only specific namespace
|
|
155
|
+
|
|
156
|
+
Examples:
|
|
157
|
+
$0 # Process all namespaces
|
|
158
|
+
$0 -e # Show available endpoints
|
|
159
|
+
$0 -n examples@wikidata.org # Process only specific namespace
|
|
160
|
+
EOF
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
# Parse command line arguments
|
|
164
|
+
DRY_RUN=false
|
|
165
|
+
SPECIFIC_NAMESPACE=""
|
|
166
|
+
|
|
167
|
+
while [[ $# -gt 0 ]]; do
|
|
168
|
+
case $1 in
|
|
169
|
+
-h|--help)
|
|
170
|
+
show_usage
|
|
171
|
+
exit 0
|
|
172
|
+
;;
|
|
173
|
+
-e|--endpoints)
|
|
174
|
+
show_available_endpoints
|
|
175
|
+
exit 0
|
|
176
|
+
;;
|
|
177
|
+
-d|--dry-run)
|
|
178
|
+
DRY_RUN=true
|
|
179
|
+
shift
|
|
180
|
+
;;
|
|
181
|
+
-n|--namespace)
|
|
182
|
+
SPECIFIC_NAMESPACE="$2"
|
|
183
|
+
shift 2
|
|
184
|
+
;;
|
|
185
|
+
*)
|
|
186
|
+
echo "Unknown option: $1"
|
|
187
|
+
show_usage
|
|
188
|
+
exit 1
|
|
189
|
+
;;
|
|
190
|
+
esac
|
|
191
|
+
done
|
|
192
|
+
|
|
193
|
+
# Main execution
|
|
194
|
+
if [ "$DRY_RUN" = true ]; then
|
|
195
|
+
echo "DRY RUN MODE - Commands that would be executed:"
|
|
196
|
+
# Override run_snapquery for dry run
|
|
197
|
+
run_snapquery() {
|
|
198
|
+
local domain="$1"
|
|
199
|
+
local namespace="$2"
|
|
200
|
+
local endpoint="$3"
|
|
201
|
+
echo "Would run: snapquery -d -tq -en '$endpoint' --context 'cmd_line_tests' --domain '$domain' --namespace '$namespace'"
|
|
202
|
+
}
|
|
203
|
+
fi
|
|
204
|
+
|
|
205
|
+
if [ -n "$SPECIFIC_NAMESPACE" ]; then
|
|
206
|
+
# Process specific namespace
|
|
207
|
+
local namespace="${SPECIFIC_NAMESPACE%%@*}"
|
|
208
|
+
local domain="${SPECIFIC_NAMESPACE#*@}"
|
|
209
|
+
echo "Processing specific namespace: $domain/$namespace"
|
|
210
|
+
execute_queries_safe "$domain" "$namespace"
|
|
211
|
+
else
|
|
212
|
+
# Process all namespaces
|
|
213
|
+
process_namespace_data
|
|
214
|
+
fi
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.2.4"
|
|
@@ -4,9 +4,10 @@ GitHub API client for accessing repository contents.
|
|
|
4
4
|
Created on 2025-12-02
|
|
5
5
|
@author: wf
|
|
6
6
|
"""
|
|
7
|
+
|
|
7
8
|
import json
|
|
8
|
-
from
|
|
9
|
-
from typing import
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import Any, Dict, List, Optional, Union
|
|
10
11
|
|
|
11
12
|
import requests
|
|
12
13
|
|
|
@@ -16,28 +17,38 @@ class GitHub:
|
|
|
16
17
|
A simple GitHub API client for accessing repository contents.
|
|
17
18
|
"""
|
|
18
19
|
|
|
19
|
-
def __init__(
|
|
20
|
+
def __init__(
|
|
21
|
+
self,
|
|
22
|
+
owner: str,
|
|
23
|
+
repo: str,
|
|
24
|
+
branch: Optional[str] = None,
|
|
25
|
+
token: Optional[str] = None,
|
|
26
|
+
session: Optional[requests.Session] = None
|
|
27
|
+
):
|
|
20
28
|
"""
|
|
21
29
|
Initialize GitHub client.
|
|
22
30
|
|
|
23
31
|
Args:
|
|
24
32
|
owner: Repository owner (username or organization)
|
|
25
33
|
repo: Repository name
|
|
34
|
+
branch: Optional specific branch or commit SHA (default: default repo branch)
|
|
26
35
|
token: Optional GitHub API token for authentication
|
|
27
36
|
session: Optional custom requests.Session
|
|
28
37
|
"""
|
|
29
38
|
self.owner = owner
|
|
30
39
|
self.repo = repo
|
|
31
|
-
self.
|
|
40
|
+
self.branch = branch
|
|
41
|
+
|
|
42
|
+
|
|
32
43
|
self.base_url = f"https://api.github.com/repos/{owner}/{repo}"
|
|
33
|
-
|
|
44
|
+
|
|
45
|
+
# Use provided token or read from file
|
|
34
46
|
self.token = token if token is not None else self._read_token()
|
|
35
47
|
|
|
36
48
|
# Use custom session or create new one
|
|
37
49
|
self.session = session or requests.Session()
|
|
38
50
|
|
|
39
51
|
|
|
40
|
-
|
|
41
52
|
def _headers(self) -> Dict[str, str]:
|
|
42
53
|
headers = {"Accept": "application/vnd.github.v3+json"}
|
|
43
54
|
if self.token:
|
|
@@ -55,14 +66,13 @@ class GitHub:
|
|
|
55
66
|
token_path = Path.home() / ".github" / "access_token.json"
|
|
56
67
|
if token_path.exists():
|
|
57
68
|
try:
|
|
58
|
-
with open(token_path,
|
|
69
|
+
with open(token_path, "r") as f:
|
|
59
70
|
data = json.load(f)
|
|
60
71
|
return data.get("access_token")
|
|
61
72
|
except (json.JSONDecodeError, OSError):
|
|
62
73
|
pass
|
|
63
74
|
return None
|
|
64
75
|
|
|
65
|
-
|
|
66
76
|
def get_contents(self, path: str = "") -> Union[List[Dict[str, Any]], Dict[str, Any]]:
|
|
67
77
|
"""
|
|
68
78
|
Get contents of a directory or file from the repository.
|
|
@@ -74,10 +84,15 @@ class GitHub:
|
|
|
74
84
|
List of dictionaries for directories, or content for files
|
|
75
85
|
"""
|
|
76
86
|
url = f"{self.base_url}/contents/{path}"
|
|
77
|
-
|
|
87
|
+
params = {}
|
|
88
|
+
if self.branch:
|
|
89
|
+
params["ref"] = self.branch
|
|
90
|
+
|
|
91
|
+
response = self.session.get(url, headers=self._headers(), params=params, timeout=30)
|
|
78
92
|
response.raise_for_status()
|
|
79
93
|
return response.json()
|
|
80
94
|
|
|
95
|
+
|
|
81
96
|
def list_files_recursive(self, path: str = "", suffix: Optional[str] = None) -> List[Dict[str, Any]]:
|
|
82
97
|
"""
|
|
83
98
|
Recursively list files under a given path. Optionally filter by file suffix.
|
|
@@ -116,4 +131,4 @@ class GitHub:
|
|
|
116
131
|
"""
|
|
117
132
|
response = self.session.get(download_url, headers=self._headers(), timeout=30)
|
|
118
133
|
response.raise_for_status()
|
|
119
|
-
return response.text
|
|
134
|
+
return response.text
|