NucliaDB SDK
Actively maintained. Last release 3 days ago, commits in 26 of the last 26 weeks. A safe choice.
pip install nucliadb-sdkNucliaDB SDK
The NucliaDB SDK is a Python library designed as a thin wrapper around the NucliaDB HTTP API. It is tailored for developers who wish to create low-level scripts to interact with NucliaDB.
WARNING
⚠ If it's your first time using Nuclia or you want a simple way to push your unstructured data to Nuclia with a script or a CLI, we highly recommend using the Nuclia CLI/SDK instead, as it is much more user-friendly and use-case focused. ⚠
Installation
To install it, simply with pip:
pip install nucliadb-sdk
How to use it?
To connect to a Nuclia-hosted NucliaDB instance, just use the NucliaDB constructor method with the api_key:
from nucliadb_sdk import NucliaDB, Region
ndb = NucliaDB(region=Region.EUROPE1, api_key="my-api-key")
Alternatively, to connect to a NucliaDB local installation, use:
ndb = NucliaDB(region=Region.ON_PREM, api="http://localhost:8080/api")
Then, each method of the NucliaDB class maps to an HTTP endpoint of the NucliaDB API. The parameters it accepts correspond to the Pydantic models associated to the request body scheme of the endpoint.
The method-to-endpoint mappings for the sdk are declared in-code in the _NucliaDBBase class.
For instance, to create a resource in your Knowledge Box, the endpoint is defined here.
It has a {kbid} path parameter and is expecting a json payload with some optional keys like slug or title, that are of type string. With curl, the command would be:
curl -XPOST http://localhost:8080/api/v1/kb/my-kbid/resources -H 'x-nucliadb-roles: WRITER' --data-binary '{"slug":"my-resource","title":"My Resource"}' -H "Content-Type: application/json"
{"uuid":"fbdb10a79abc45c0b13400f5697ea2ba","seqid":1}
and with the NucliaDB sdk:
>>> from nucliadb_sdk import NucliaDB
>>>
>>> ndb = NucliaDB(region="on-prem", url="http://localhost:8080/api")
>>> ndb.create_resource(kbid="my-kbid", slug="my-resource", title="My Resource")
ResourceCreated(uuid='fbdb10a79abc45c0b13400f5697ea2ba', elapsed=None, seqid=1)