sparql-api-codegen
Automatically generate python API package from a SPARQL endpoint VoID description
Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (12.7%) to scientific vocabulary
Keywords
Repository
Automatically generate python API package from a SPARQL endpoint VoID description
Basic Info
Statistics
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
- Releases: 0
Topics
Metadata Files
README.md
A CLI tool to automatically generate a python package from a SPARQL endpoint VoID description.
It will generate a folder with all requirements for publishing a modern python package containing the classes to automatically work with the data in the endpoint.
Features:
- Each class in the endpoint will be defined as a python class, with fields for each predicates available on a class.
- It will use the classes and predicates labels from their ontology when possible to generate the python classes and their fields
- Type annotations are used for better autocompletion
- Fields of a class are retrieved when the field is called (lazy 🦥)
🪄 Usage
Requirements: Python >=3.9
- Install the package with
piporpipx:
sh
pipx install sparql-api-codegen
- Generate the code for a SPARQL endpoint which contains a SPARQL Service Description:
sh
sparql-api-codegen <sparql-endpoint-url> <folder-for-generated-python-pkg> -i <iri-of-class-to-ignore>
- Once the folders have been generated you can get into the folder, check and improve the instructions to run in the
README.md, improve the metadata in thepyproject.toml
Optionally you can ignore some classes. For some endpoints this will be required if the label generated for 2 classes are identical, e.g. for Bgee:
sh
sparql-api-codegen "https://www.bgee.org/sparql/" "bgee-api" \
-i http://purl.obolibrary.org/obo/CARO_0000000 \
-i http://purl.obolibrary.org/obo/SO_0000704 \
-i http://purl.obolibrary.org/obo/NCIT_C14250
Example python API for Bgee:
```python from bgee_api import AnatomicalEntity, Gene, GeneExpressionExperimentCondition
if name == "main": allanats = AnatomicalEntity.get() print(len(allanats), all_anats[0])
anat = AnatomicalEntity("http://purl.obolibrary.org/obo/AEO_0000013")
print(anat)
print(anat.label)
print(anat.expresses)
gene= Gene("http://omabrowser.org/ontology/oma#GENE_ENSMUSG00000053483")
print(gene.label)
cond = GeneExpressionExperimentCondition("http://bgee.org/#EXPRESSION_CONDITION_101909")
print(cond.has_a_developmental_stage)
print(cond.has_anatomical_entity)
```
For UniProt:
sh
sparql-api-codegen "https://sparql.uniprot.org/sparql/" "uniprot-api" \
-i http://biohackathon.org/resource/faldo#Region
🧑💻 Development setup
The final section of the README is for if you want to run the package in development, and get involved by making a code contribution.
📥️ Clone
Clone the repository:
bash
git clone https://github.com/TRIPLE-CHIST-ERA/sparql-api-codegen
cd sparql-api-codegen
🐣 Install dependencies
Install Hatch, a modern build system, as well as project and virtual env management tool recommended by the Python Packaging Authority. This will automatically handle virtual environments and make sure all dependencies are installed when you run a script in the project:
bash
pipx install hatch
Or you could install in your favorite virtual env:
bash
pip install -e ".[test]"
🛠️ Develop
Test with the Bgee endpoint:
bash
hatch run sparql-api-codegen "https://www.bgee.org/sparql/" "bgee-api" \
-i http://purl.obolibrary.org/obo/CARO_0000000 \
-i http://purl.obolibrary.org/obo/SO_0000704 \
-i http://purl.obolibrary.org/obo/NCIT_C14250
☑️ Run tests
Make sure the existing tests still work by running the test suite and linting checks. Note that any pull requests to the fairworkflows repository on github will automatically trigger running of the test suite;
bash
hatch run test
To display all logs when debugging:
bash
hatch run test -s
♻️ Reset the environment
In case you are facing issues with dependencies not updating properly you can easily reset the virtual environment with:
bash
hatch env prune
Manually trigger installing the dependencies in a local virtual environment:
bash
hatch -v env create
🏷️ New release process
The deployment of new releases is done automatically by a GitHub Action workflow when a new release is created on GitHub. To release a new version:
- Make sure the
PYPI_TOKENsecret has been defined in the GitHub repository (in Settings > Secrets > Actions). You can get an API token from PyPI at pypi.org/manage/account. Increment the
versionnumber in thepyproject.tomlfile in the root folder of the repository.bash hatch version fixCreate a new release on GitHub, which will automatically trigger the publish workflow, and publish the new release to PyPI.
You can also build and publish from your computer:
bash
hatch build
hatch publish
TODO
- Bulk load with preloaded fields
python
all_anats_preloaded: list[AnatomicalEntity] = bulk_load(AnatomicalEntity, ["label", "expresses"])
# Or
all_anats_preloaded: list[AnatomicalEntity] = AnatomicalEntity.get(["label", "expresses"])
Allow also to pass a list of IRI (optional, if not we get all?)
- Returns pandas matrix with filters?
python
pandas_matrix = BiologicalEntity.get_matrix(
filter_has_a_developmental_stage="http://some_dev_stage",
filter_has_anatomical_entity="some anatomical entity",
)
Also enable to filter on labels instead of IRI?
Owner
- Name: TRIPLE-CHIST-ERA
- Login: TRIPLE-CHIST-ERA
- Kind: organization
- Repositories: 1
- Profile: https://github.com/TRIPLE-CHIST-ERA
Citation (CITATION.cff)
cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
- orcid: https://orcid.org/0000-0002-1501-1082
email: vincent.emonet@sib.swiss
given-names: Vincent Emonet
# affiliation: Institute of Data Science, Maastricht University
title: "SPARQL VoID to python API"
repository-code: https://github.com/TRIPLE-CHIST-ERA/sparql-api-codegen
date-released: 2024-11-05
url: https://pypi.org/project/sparql-api-codegen
# doi: 10.48550/arXiv.0000.00000
GitHub Events
Total
- Push event: 1
Last Year
- Push event: 1
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 0
- Total pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Total issue authors: 0
- Total pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 12 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 1
- Total maintainers: 1
pypi.org: sparql-api-codegen
Automatically generate python API package from a SPARQL endpoint using its VoID descriptive metadata
- Homepage: https://github.com/TRIPLE-CHIST-ERA/sparql-api-codegen
- Documentation: https://github.com/TRIPLE-CHIST-ERA/sparql-api-codegen
- License: MIT License Copyright (c) 2024-present SIB Swiss Institute of Bioinformatics Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
Latest release: 0.0.1
published about 1 year ago
Rankings
Maintainers (1)
Dependencies
- actions/checkout v4 composite
- actions/setup-python v4 composite
- PyYAML *
- requests *
- typer >=0.6.0