PyStardog

raw JSON →
0.20.0 verified Mon Apr 27 auth: no python

Python client for Stardog Knowledge Graph Platform endpoints and Stardog Cloud. Current version 0.20.0, requires Python >=3.9. Release cadence is irregular; breaking changes occur between minor versions.

pip install pystardog
error AttributeError: module 'pystardog' has no attribute 'Stardog'
cause Wrong import: `import pystardog` instead of `from pystardog import Stardog`.
fix
Use from pystardog import Stardog.
error pystardog.exceptions.ConnectionException: Unable to connect to Stardog
cause Stardog server not running, wrong endpoint, or SSL misconfiguration.
fix
Verify endpoint URL and SSL config. For local server use http://localhost:5820.
error TypeError: __init__() got an unexpected keyword argument 'ssl'
cause Using old `ssl` parameter which was removed in 0.17.0.
fix
Use ssl_config=SSLConfig(...) instead.
breaking In version 0.17.0, the `Stardog` constructor changed from `Stardog(endpoint=..., ..., ssl=...)` to `Stardog(endpoint=..., ssl_config=...)`. Old `ssl` parameter is removed.
fix Use `ssl_config=SSLConfig(...)` instead of `ssl=True/False`.
breaking In version 0.18.0, `database.query()` no longer returns raw results by default; returns `QueryResult` object. Access via `result.results`.
fix Use `result = db.query('...'); rows = result.results`.
deprecated `Stardog.database(name)` is deprecated in favor of `Stardog.databases().get(name)`.
fix Use `sd.databases().get('myDB')` instead.
gotcha Default timeout is 30 seconds; long-running SPARQL queries may timeout. Set custom timeout when constructing Stardog client.
fix `Stardog(endpoint=..., timeout=120)`

Connect to a Stardog server and get database size. Uses environment variable for endpoint; adjust credentials as needed.

from pystardog import Stardog

sd = Stardog(endpoint=os.environ.get('STARDOG_ENDPOINT', 'http://localhost:5820'))
# Authentication optional
# sd.set_credentials('admin', 'admin')
db = sd.database('myDB')
print(db.size())