Package: pystardog
pystardoga Python wrapper for communicating with the Stardog HTTP server.Docs:http://pystardog.readthedocs.ioRequirements: Python 3.8+What is it?This library wraps all the functionality of a client for the Stardog
Knowledge Graph, and provides access to a full set of functions such
as executing SPARQL queries and many administrative tasks.The implementation uses the HTTP protocol, since most of Stardog
functionality is available using this protocol. For more information,
seeHTTP
Programmingin Stardog's documentation.Installationpystardog is onPyPI. To install:pipinstallpystardogQuick Exampleimportstardogconn_details={'endpoint':'http://localhost:5820','username':'admin','password':'admin'}withstardog.Admin(**conn_details)asadmin:db=admin.new_database('db')withstardog.Connection('db',**conn_details)asconn:conn.begin()conn.add(stardog.content.File('./test/data/example.ttl'))conn.commit()results=conn.select('select * { ?a ?p ?o }')db.drop()Interactive TutorialThere is a Jupyter notebook and instructions in thenotebooksdirectory of this repository.DocumentationDocumentation is available athttp://pystardog.readthedocs.ioBuild the Docs LocallyThe docs can be built locally usingSphinx:cddocs
pipinstall-rrequirements.txt
makehtmlAutodoc Type HintsThe docs usesphinx-autodoc-typehintswhich allows you to omit types when documenting argument/returns types of functions. For example:The following function:defdatabase(self,name:str)->"Database":"""Retrieves an object representing a database.:param name: The database name:return: the database"""returnDatabase(name,self.client)will yield the following documentation after Sphinx processes it:NoteOnly arguments that have an existing:param:directive in the docstring get their
respective:type:directives added. The:rtype:directive is added if and only if no existing:rtype:is found.
See thedocsfor additional information on how the extension works.Auto BuildDocs can be rebuilt automatically when saving a Python file by utilizingsphinx-autobuildcddocs
pipinstall-rrequirements.txtrequirements-dev.txt
makelivehtmlThis should make the docs available athttp://localhost:8000.Example output after runningmake livehtml:❯ make livehtml
sphinx-autobuild "." "_build"   --watch ../stardog/
[sphinx-autobuild] > sphinx-build /Users/frodo/projects/pystardog/docs /Users/frodo/projects/pystardog/docs/_build
Running Sphinx v6.2.1
loading pickled environment... done
building [mo]: targets for 0 po files that are out of date
writing output...
building [html]: targets for 0 source files that are out of date
updating environment: 0 added, 0 changed, 0 removed
reading sources...
looking for now-outdated files... none found
no targets are out of date.
build succeeded.

The HTML pages are in _build.
[I 230710 15:26:18 server:335] Serving on http://127.0.0.1:8000
[I 230710 15:26:18 handlers:62] Start watching changes
[I 230710 15:26:18 handlers:64] Start detecting changesContributing and DevelopmentContrbutions are always welcome to pystardog.To make a contribution:Create a new branch off ofmain. There is no set naming convention for branches but try and keep it descriptive.gitcheckout-bfeature/add-support-for-XMake your changes. If you are making substantive changes to pystardog, tests should be added to ensure your changes are working as expected. SeeRunning Testsfor additional information
about running tests.Format your code. All Python code should be formatted usingBlack. SeeFormatting Your Codefor additional information.Commit and push your code. Similar to branch names, there is no set structure for commit messages but try and keep your commit messages succinct and on topic.gitcommit-am"feat: adds support for feature X"gitpushoriginfeature/add-support-for-xCreate a pull request againstmain. All CircleCI checks should be passing in order to merge your PR. CircleCI will run tests against all supported versions of Python, single node and cluster tests for pystardog, as well as do some static analysis of the code.Running TestsRequirements:DockerDocker ComposeValid Stardog LicenseTo run the tests locally, a valid Stardog license is required and placed atdockerfiles/stardog-license-key.bin.Bring a stardog instance using docker-compose. For testing about 90% of the pystardog features, just a single node is sufficient,
although we also provide a cluster set up for further testing.# Bring a single node instance plus a bunch of Virtual Graphs for testing (Recommended).docker-compose-fdocker-compose.single-node.ymlup-d# A cluster setup is also provided, if cluster only features are to be implemented and tested.docker-compose-fdocker-compose.cluster.ymlup-dCreate a virtual environment with the necessary dependencies:# Create a virtualenv and activate itvirtualenv-p$(whichpython3)venvsourcevenv/bin/activate# Install dependenciespipinstall-rrequirements.txt-rtest-requirements.txtRun the test suite:# Run the basic test suite (covers most of the pystardog functionalities)pytesttest/test_admin_basic.pytest/test_connection.pytest/test_utils.py-sNoteTests can be targeted against a specific Stardog endpoint by specifying an--endpointoption topytest. Please note, that the tests will make modifications
to the Stardog instance like deleting users, roles, databases, etc. By default, the--endpointis set tohttp://localhost:5820,
which is where the Dockerized Stardog (defined in the Docker compose files) is configured to be available at.pytesttest/test_connection.py-ktest_queries-s--endpointhttps://my-other-stardog:5820Formatting your codeTo format all the Python code:# make sure black is installvirtualenv-p$(whichpython3)venv
.venv/bin/activate
pipinstall-rtest-requirements.txt# run black formatterblack.