Use the internal API of a RUDI Producer node
Project description
Caution: this librairy is still a work in progress.
RUDI Node tools: rudi-node-write library
This library offers tools to take advantage of the internal API of a RUDI Producer node ( also referred as RUDI node).
Installation
$ pip install rudi_node_write
Authentication
To use the RUDI node internal API /api/admin/...
, you'll need an authentication JWT in every header request.
This library provides a RudiNodeJwtFactory
connector that calls a JWT
server running locally or on the RUDI
node to create/renew the JWT.
rudi_node_credentials = {
"url": "<rudi node url>",
"usr": "<my user name>", # either use 'usr' & 'pwd', or the base64url encoded usr:pwd pair in 'b64auth'
"pwd": "<my password>",
"b64auth": "<base64url encoded usr:pwd pair>" # optional / alternative way of declaring the usr:pwd pair
}
from rudi_node_write.connectors.io_rudi_jwt_factory import RudiNodeJwtFactory
node_jwt_factory = RudiNodeJwtFactory(rudi_node_credentials["url"], rudi_node_credentials)
Usage: RudiNodeApiConnector
One can create, read, update or delete metadata with a RudiNodeApiConnector object using the [RUDI API](. /doc/rudi-api/RUDI producer internal API - 1.3.0.yml).
from rudi_node_write.connectors.io_rudi_jwt_factory import RudiNodeJwtFactory
from rudi_node_write.connectors.io_rudi_api_write import RudiNodeApiConnector
rudi_node_url = 'https://bacasable.fenix.rudi-univ-rennes1.fr'
node_jwt_factory = RudiNodeJwtFactory(rudi_node_url, {"usr": "<my user name>", "pwd": "<my password>"})
rudi_api = RudiNodeApiConnector(server_url=rudi_node_url, jwt_factory=node_jwt_factory)
print("metadata count:", rudi_api.metadata_count)
print("metadata alt count:", len(rudi_api.metadata_list))
print("metadata producers declared on the node:", rudi_api.producer_names)
print("searching a metadata with a file name:", rudi_api.find_metadata_with_media_name('toucan.jpg'))
Usage: RudiNodeMediaConnector
The upload of file is done with a RudiNodeMediaConnector that let you connect to a RUDI node Media server. This also needs an authentication in the request header, that is created with the RudiMediaHeadersFactoryBasicAuth object.
from rudi_node_write.connectors.io_rudi_media_write import RudiMediaHeadersFactoryBasicAuth, RudiNodeMediaConnector
rudi_node_url = 'https://bacasable.fenix.rudi-univ-rennes1.fr'
media_headers_factory = RudiMediaHeadersFactoryBasicAuth(usr="<my user name>", pwd="<my password>")
rudi_media = RudiNodeMediaConnector(server_url=rudi_node_url, headers_factory=media_headers_factory)
print("listing the media stored on the RUDI node: ", rudi_media.media_list)
Testing
The tests can be analyzed for further information about how to call the "RUDI API" and the "RUDI Media" servers.
$ pytest
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for rudi_node_write-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab0a784bc039764d883aeb04cdc80dd7e3d41581df0aac8143cf38c3a5d0b297 |
|
MD5 | f681a11edb7ce2fc479d765aa71c2462 |
|
BLAKE2b-256 | 57021a878538e0f0ec7952e1bc1c290486f814cf2ac3a7a483eeac023d05b5be |