Skip to content

feat: 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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,20 @@
# ones.
extensions = [
"sphinx.ext.autodoc",
"sphinxcontrib.autodoc_pydantic",
"sphinx_autodoc_typehints",
"sphinx.ext.doctest",
"sphinx.ext.viewcode",
"sphinx.ext.napoleon",
"recommonmark",
]

# https://autodoc-pydantic.readthedocs.io/en/stable/users/installation.html
autodoc_pydantic_model_show_json = False
autodoc_pydantic_settings_show_json = False
autosummary_generate = True


# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]

Expand Down
2 changes: 2 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ pystardog

README.md
source/stardog
source/stardog.cloud


Indices and tables
==================
Expand Down
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ contextlib2==21.6.0
requests-toolbelt==1.0.0
recommonmark==0.5.0
requests==2.31.0
autodoc_pydantic==2.2.0
105 changes: 105 additions & 0 deletions docs/source/stardog.cloud.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
Stardog Cloud
###############

The :obj:`stardog.cloud` subpackage provides clients for accessing Stardog Cloud services, such as `Stardog Voicebox <https://stardog.ai/>`_.

.. list-table:: Clients
:widths: 50 50
:header-rows: 1

* - Class
- Description
* - :class:`stardog.cloud.client.Client`
- Ideal for simple blocking operations in traditional Python applications.
* - :class:`stardog.cloud.client.AsyncClient`
- Suitable for async programming models, such as ``asyncio``.

Voicebox Integration
************************

Access Stardog's Voicebox capabilities through an instance of :class:`stardog.cloud.voicebox.VoiceboxApp` class.

.. note::
The :class:`stardog.cloud.voicebox.VoiceboxApp` provides both synchronous and asynchronous methods, offering the same functionality. Asynchronous methods are prefixed with `async_` and return coroutines that can be awaited, while synchronous methods return objects directly. For example, :obj:`stardog.cloud.voicebox.VoiceboxApp.async_ask` returns a coroutine, while :obj:`stardog.cloud.voicebox.VoiceboxApp.ask` returns a :class:`stardog.cloud.voicebox.VoiceboxAnswer`.



Synchronous usage
========================

.. code-block:: python

from stardog.cloud.client import Client

with Client() as client:
app = client.voicebox_app(app_api_token="your-token", client_id="your-client-id")
response = app.ask(question="Your question here")

Asynchronous usage
========================


.. code-block:: python

from stardog.cloud.client import AsyncClient

async with AsyncClient() as client:
app = client.voicebox_app(app_api_token="your-token", client_id="your-client-id")
response = await app.async_ask(question="Your question here")


Error Handling
========================

The package raises custom exceptions defined in the :obj:`stardog.cloud.exceptions` module. These exceptions can be caught when interacting with the Stardog Cloud clients.

All clients raise exceptions if needed, with :class:`stardog.cloud.exceptions.StardogCloudException` serving as the base exception for any error raised.

.. code-block:: python

from stardog.cloud.exceptions import (
StardogCloudException,
RateLimitExceededException
)

try:
with Client() as client:
app = client.voicebox_app(app_api_token="your-token", client_id="your-client-id")
response = app.ask(question="Your question")
except RateLimitExceededException as e:
print(f"Rate limit exceeded: {e}")
except StardogCloudException as e:
print(f"Error occurred: {e}")



API Reference
*********************

stardog.cloud.client
============================

.. automodule:: stardog.cloud.client
:members:
:undoc-members:
:show-inheritance:
:special-members: __init__

stardog.cloud.voicebox
============================

.. automodule:: stardog.cloud.voicebox
:members:
:undoc-members:
:show-inheritance:
:special-members: __init__

stardog.cloud.exceptions
============================

.. automodule:: stardog.cloud.exceptions
:members:
:undoc-members:
:show-inheritance:
:special-members: __init__

18 changes: 11 additions & 7 deletions docs/source/stardog.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
Modules
=======
Stardog
#######


API Reference
*********************

stardog.connection
------------------
==================

.. automodule:: stardog.connection
:members:
Expand All @@ -11,7 +15,7 @@ stardog.connection
:special-members: __init__

stardog.admin
-------------
=============

.. automodule:: stardog.admin
:members:
Expand All @@ -20,7 +24,7 @@ stardog.admin
:special-members: __init__

stardog.content
---------------
===============

.. automodule:: stardog.content
:members:
Expand All @@ -29,7 +33,7 @@ stardog.content
:special-members: __init__

stardog.results
---------------
===============

.. automodule:: stardog.results
:members:
Expand All @@ -38,7 +42,7 @@ stardog.results
:special-members: __init__

stardog.exceptions
------------------
==================

.. automodule:: stardog.exceptions
:members:
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ requests-toolbelt==1.0.0
contextlib2==0.5.5
recommonmark==0.5.0
rdflib>=6.0.0
httpx>=0.27.0
pydantic>=2.7.0
3 changes: 3 additions & 0 deletions stardog/cloud/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .client import AsyncClient, Client

__all__ = ["AsyncClient", "Client"]
Loading