-
Notifications
You must be signed in to change notification settings - Fork 17
VBX-292: add APIs for working with Stardog Cloud public API #176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
2ad5874
fix doc issue for unrelated changes
noahgorstein e5f3f24
add new subpackage for working with the Stardog Cloud public API
noahgorstein dec44a1
add docs for working with the stardog cloud package
noahgorstein 4cc1687
improve sphinx navigation with collapsible sidebar
noahgorstein 58ffe8e
add dedicated getting started documentation page
noahgorstein 5a04054
add comprehensive contributing documentation
noahgorstein 489e4e7
restructure documentation with better organization and branding
noahgorstein 77fd4f6
improve module documentation with better descriptions
noahgorstein d88b954
update README with cloud examples and better structure
noahgorstein 0f649f3
add cloud dependencies and documentation requirements
noahgorstein 64f68f1
Add configurable timeout support to Client and AsyncClient
noahgorstein ccef626
Add comprehensive tests for cloud client and voicebox functionality
noahgorstein 88a57c6
Add pytest-asyncio and pytest-cov to dev dependencies
noahgorstein 356e29d
Add auth token override support and flexible model validation
noahgorstein 61df91a
format
noahgorstein 6ddf2ee
streamline getting started documentation
noahgorstein c775550
update documentation theme and branding
noahgorstein 742ea12
update sphinx-rtd-theme to 3.0.2
noahgorstein e9b9e26
streamline README by removing redundant sections
noahgorstein 1b16366
update project description to mention Stardog Cloud
noahgorstein fcbd09d
Add UUID validation for conversation_id parameter
noahgorstein 7e1a9f0
Add test for invalid conversation_id validation
noahgorstein 5723718
Add interactive Voicebox example
noahgorstein 729db32
add vhs tape and generated gif
noahgorstein dc36a34
Add Voicebox demo section to README
noahgorstein f92d713
Add Voicebox demo to getting started docs
noahgorstein 5a3543e
format
noahgorstein f9792a3
add respx test dependency
noahgorstein 3a7a139
add base_url property and fix endpoint enum usage
noahgorstein 9486b8a
update client tests for base_url property
noahgorstein 2345c6b
refactor voicebox tests with respx mocking
noahgorstein b1101c4
Update docs/conf.py
noahgorstein 10394ae
Update stardog/cloud/client.py
noahgorstein be6a16d
Update pyproject.toml
noahgorstein ce666bf
Update stardog/cloud/client.py
noahgorstein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,253 +1,39 @@ | ||
| # pystardog | ||
| [](https://badge.fury.io/py/pystardog) | ||
|
|
||
| a Python wrapper for communicating with the Stardog HTTP server. | ||
|
|
||
| **Docs**: [http://pystardog.readthedocs.io](http://pystardog.readthedocs.io) | ||
| Python client for Stardog servers and Stardog Cloud. | ||
|
|
||
| **Requirements**: Python 3.9+ | ||
|
|
||
| ## 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, | ||
| see [HTTP | ||
| Programming](https://docs.stardog.com/developing/http-api) | ||
| in Stardog's documentation. | ||
| ## Quick Start | ||
|
|
||
| ## Installation | ||
|
|
||
| pystardog is on [PyPI](https://pypi.org/project/pystardog/). To install: | ||
| Install from PyPI: | ||
|
|
||
| ```shell | ||
| pip install pystardog | ||
| ``` | ||
|
|
||
| ## Quick Example | ||
|
|
||
| ```python | ||
| import stardog | ||
|
|
||
| conn_details = { | ||
| 'endpoint': 'http://localhost:5820', | ||
| 'username': 'admin', | ||
| 'password': 'admin' | ||
| } | ||
|
|
||
| with stardog.Admin(**conn_details) as admin: | ||
| db = admin.new_database('db') | ||
|
|
||
| with stardog.Connection('db', **conn_details) as conn: | ||
| conn.begin() | ||
| conn.add(stardog.content.File('./test/data/example.ttl')) | ||
| conn.commit() | ||
| results = conn.select('select * { ?a ?p ?o }') | ||
|
|
||
| db.drop() | ||
| ``` | ||
|
|
||
| ## Interactive Tutorial | ||
|
|
||
| There is a Jupyter notebook and instructions in the [`notebooks`](./notebooks) | ||
| directory of this repository. | ||
|
|
||
| ## Documentation | ||
|
|
||
| Documentation is available at [http://pystardog.readthedocs.io](http://pystardog.readthedocs.io) | ||
|
|
||
| ### Build the Docs Locally | ||
|
|
||
| The docs can be built locally using [Sphinx](https://www.sphinx-doc.org/en/master/): | ||
|
|
||
| ```shell | ||
| pip install -e ".[docs]" | ||
| cd docs | ||
| make html | ||
| ``` | ||
|
|
||
| #### Autodoc Type Hints | ||
|
|
||
| The docs use [`sphinx-autodoc-typehints`](https://github.com/tox-dev/sphinx-autodoc-typehints) which allows you to omit types when documenting argument/returns types of functions. For example: | ||
|
|
||
| The following function: | ||
|
|
||
| ```python | ||
| def database(self, name: str) -> "Database": | ||
| """Retrieves an object representing a database. | ||
|
|
||
| :param name: The database name | ||
|
|
||
| :return: the database | ||
| """ | ||
| return Database(name, self.client) | ||
| ``` | ||
|
|
||
| will yield the following documentation after Sphinx processes it: | ||
|
|
||
|  | ||
|
|
||
| > **Note** | ||
| > Only 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 the [docs](https://github.com/tox-dev/sphinx-autodoc-typehints) for additional information on how the extension works. | ||
|
|
||
| #### Auto Build | ||
|
|
||
| Docs can be rebuilt automatically when saving a Python file by utilizing [`sphinx-autobuild`](https://github.com/executablebooks/sphinx-autobuild) | ||
| For Stardog Cloud functionality: | ||
|
|
||
| ```shell | ||
| pip install -e ".[docs]" | ||
| cd docs | ||
| make livehtml | ||
| pip install pystardog[cloud] | ||
| ``` | ||
|
|
||
| This should make the docs available at [http://localhost:8000](http://localhost:8000). | ||
|
|
||
| Example output after running `make livehtml`: | ||
|
|
||
| ```text | ||
| ❯ 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 changes | ||
| ``` | ||
|
|
||
| ## Contributing and Development | ||
|
|
||
| Contrbutions are always welcome to pystardog. | ||
|
|
||
| To make a contribution: | ||
|
|
||
| 1. Create a new branch off of `main`. There is no set naming convention for branches but try and keep it descriptive. | ||
|
|
||
| ```bash | ||
| git checkout -b feature/add-support-for-X | ||
| ``` | ||
|
|
||
| 2. Make your changes. If you are making substantive changes to pystardog, tests should be added to ensure your changes are working as expected. See [Running Tests](#running-tests) for additional information | ||
| about running tests. | ||
|
|
||
| 3. Format your code. All Python code should be formatted using [Black](https://pypi.org/project/black/). See [Formatting Your Code](#formatting-your-code) for additional information. | ||
|
|
||
| 4. 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. | ||
|
|
||
| ```bash | ||
| git commit -am "feat: adds support for feature X" | ||
| git push origin feature/add-support-for-x | ||
| ``` | ||
|
|
||
| 5. Create a pull request against `main`. 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 Tests | ||
|
|
||
| #### Requirements: | ||
|
|
||
| - [Docker](https://docs.docker.com/) | ||
| - [Docker Compose](https://docs.docker.com/compose/) | ||
| - Valid Stardog License | ||
|
|
||
| To run the tests locally, a valid Stardog license is required and placed at `dockerfiles/stardog-license-key.bin`. | ||
|
|
||
| 1. 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. | ||
|
|
||
| ```shell | ||
| # Bring a single node instance plus a bunch of Virtual Graphs for testing (Recommended). | ||
| docker-compose -f docker-compose.single-node.yml up -d | ||
|
|
||
| # A cluster setup is also provided, if cluster only features are to be implemented and tested. | ||
| docker-compose -f docker-compose.cluster.yml up -d | ||
| ``` | ||
|
|
||
| 2. Install the package in development mode with dependencies: | ||
|
|
||
| ```shell | ||
| # Create a virtual environment and activate it | ||
| python -m venv venv | ||
| source venv/bin/activate | ||
|
|
||
| # Install in development mode with dev dependencies | ||
| pip install -e ".[dev]" | ||
| ``` | ||
|
|
||
| 3. Run the test suite: | ||
|
|
||
| ```shell | ||
| # Run the basic test suite (covers most of the pystardog functionalities) | ||
| pytest test/test_admin_basic.py test/test_connection.py test/test_utils.py -s | ||
| ``` | ||
|
|
||
| > **Note** | ||
| > Tests can be targeted against a specific Stardog endpoint by specifying an `--endpoint` option to `pytest`. Please note, that the tests will make modifications | ||
| > to the Stardog instance like deleting users, roles, databases, etc. By default, the `--endpoint` is set to `http://localhost:5820`, | ||
| > which is where the Dockerized Stardog (defined in the Docker compose files) is configured to be available at. | ||
| > | ||
| > ```bash | ||
| > pytest test/test_connection.py -k test_queries -s --endpoint https://my-other-stardog:5820 | ||
| > ``` | ||
|
|
||
| ### Formatting your code | ||
|
|
||
| To format all the Python code: | ||
|
|
||
| ```shell | ||
| # Create and activate virtual environment | ||
| python -m venv venv | ||
| source venv/bin/activate | ||
| pip install -e ".[dev]" | ||
|
|
||
| # run black formatter | ||
| black . | ||
| ``` | ||
|
|
||
| ### Running Tests with Tox | ||
|
|
||
| To run tests across multiple Python versions: | ||
|
|
||
| ```shell | ||
| # Run tests for all supported Python versions | ||
| tox | ||
|
|
||
| # Run tests for a specific Python version | ||
| tox -e py312 | ||
| ## Documentation | ||
|
|
||
| # Run cluster-specific tests | ||
| tox -e cluster | ||
| **Full documentation**: [http://pystardog.readthedocs.io](http://pystardog.readthedocs.io) | ||
|
|
||
| # Run single-node-specific tests | ||
| tox -e single_node | ||
| ``` | ||
| - [**Getting Started**](http://pystardog.readthedocs.io/en/latest/getting-started.html) - Installation, examples, and basic usage | ||
| - [**API Reference**](http://pystardog.readthedocs.io/en/latest/source/stardog.html) - Complete API documentation | ||
| - [**Contributing**](http://pystardog.readthedocs.io/en/latest/contributing.html) - Development setup, testing, and contribution guidelines | ||
|
|
||
| ### Building and Publishing | ||
| ## Interactive Tutorial | ||
|
|
||
| To build and publish the package to PyPI: | ||
| There is a Jupyter notebook and instructions in the [`notebooks`](./notebooks) directory of this repository. | ||
|
|
||
| ```shell | ||
| # Install build dependencies | ||
| pip install -e ".[build]" | ||
| ## Voicebox Demo | ||
|
|
||
| # Build the package | ||
| python -m build | ||
| Interactive example showing natural language queries with Stardog Cloud's Voicebox ([`examples/voicebox_example.py`](examples/voicebox_example.py)): | ||
|
|
||
| # Upload to PyPI (requires authentication) | ||
| twine upload dist/* | ||
| ``` | ||
|  | ||
|
|
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some doc cleanup included here too while I was adding the new docs for cloud.