Nanospace-client
Python client
Requirement
Request package is needed
pip install requests
Simple examle
Check simple_example.py. Before try to launch it, think to change the login, password and srvUrl in the file. Think to end the address with a '/'.
from nanospace import Nanospace
nanospace = Nanospace('http://yourSrvUrl/','yourUsername', 'yourPassword')
print(nanospace.get_string_value(66))
nanospace.update_value(66, 'sma', '9000000')
print(nanospace.get_string_value(66)) # 9000000
print(nanospace.get_formula_value(66))
nanospace.update_value(77, 'sma', '9000000')
print(nanospace.get_formula_value(66)) # 9000000
Creation of element
It is also possibile to create component, value, and modes from python. However, we advice to use the UI instead.
# from nanospace import Nanospace
# nanospace = Nanospace('http://yourSrvUrl/','yourUsername', 'yourPassword')
nanospace._create_component(12, 'new_component)
nanospace._create_mode(12, my_new_mode)
nanospace._create_string_value(45, '')
If the id is missing check the nanospace_ui url can help you to get one. Then each one of the create function are returning a python dictionary where you can find id.
Delete a element
Even if it is advise to delete element from the UI we give also the possibilities to delete element from python.
# from nanospace import Nanospace
# nanospace = Nanospace('http://yourSrvUrl/','yourUsername', 'yourPassword')
nanospace._delete_component(12)
nanospace._delete_mode(45)
nanospace._delete_value(63)
Note that delete_value is working either if the value is a formula, or a string
Bash client
Get your login
Request (replace yourLogin and yourPassword by your real login and pw) :
curl -X POST \
http://localhost:8888/login \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/json' \
-d '{
"username":"'"yourLogin"'",
"password":"'"yourPassword"'"
}' | grep Bearer
Response :
Authorization: Bearer --TokenId-- # Token Result
The result is giving you a token to access to your account.
Get a value
Copy paste the full result of the login as header and add the number of the value you want to get
curl GET \
http://localhost:8888/value/71 \
-H 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJsdWNpZW4iLCJleHAiOjE1NTYzNjcyODF9.a3iv6yGzOcbPfAs_vHCUpo2zJJtrl23Kn_HA1tn_zBvKI86o2zE0V50H_GqyIzp5VmLSVuU93O8OtBLGClZxRA' \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJsdWNpZW4iLCJleHAiOjE1NTg2MjI4Nzl9.4ohO9F55GgxzyKim-K0xQKkBiW-me_v6K74b4YLIOVdg1xiPsrOVkmqg_-VWu7W4_l00XWXXjguccmXLxQi-Ow' | grep value
Update a value
#Todo