Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
nanospace-python-client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nanostar
nanospace
nanospace-clients
nanospace-python-client
Commits
19556750
Commit
19556750
authored
6 months ago
by
DHOMBRES Stephanie
Browse files
Options
Downloads
Patches
Plain Diff
Update example and URL for demo
parent
8ef1ef76
Branches
Branches containing commit
No related tags found
1 merge request
!1
Dev update
Changes
5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
COPYRIGHT
+2
-2
2 additions, 2 deletions
COPYRIGHT
README.md
+16
-13
16 additions, 13 deletions
README.md
auth_test.py
+38
-0
38 additions, 0 deletions
auth_test.py
nanospace.py
+192
-291
192 additions, 291 deletions
nanospace.py
simple_example.py
+85
-16
85 additions, 16 deletions
simple_example.py
with
333 additions
and
322 deletions
COPYRIGHT
+
2
−
2
View file @
19556750
JSatOrb: Simplified Mission Analysis REST-based Tool Dedicated to Education and Training
NanoSpace Python Client: API functions to exchange data with back-end
Copyright (C) 2019 ISAE-SUPAERO
Copyright (C) 2019
-2025
ISAE-SUPAERO
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
...
...
This diff is collapsed.
Click to expand it.
README.md
+
16
−
13
View file @
19556750
# Nanospace-client
## Python client
### Requirement
Request package is needed
```
bash
sudo
apt
install
python3 python3-pip python-is-python3
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 '/'.
Check the
`simple_example.py`
python file.
Before try to launch it, change the
`username`
,
`password`
and
`server`
address (End the server address with a '/').
```
python
from
nanospace
import
Nanospace
nanospace
=
Nanospace
(
'
http://
yourSrvUrl/
'
,
'
yourU
sername
'
,
'
yourP
assword
'
)
nanospace
=
Nanospace
(
'
http://
server_address/
'
,
'
u
sername
'
,
'
p
assword
'
)
print
(
nanospace
.
get_string_value
(
66
))
nanospace
.
update_value
(
66
,
'
sma
'
,
'
9000000
'
)
print
(
nanospace
.
get_string_value
(
66
))
# 9000000
print
(
nanospace
.
get_string_value
(
66
))
#
Should print
9000000
print
(
nanospace
.
get_formula_value
(
66
))
nanospace
.
update_value
(
77
,
'
sma
'
,
'
9000000
'
)
print
(
nanospace
.
get_formula_value
(
66
))
# 9000000
print
(
nanospace
.
get_formula_value
(
66
))
#
Should print
9000000
```
### Creation of element
It is also possib
i
le to create component, value
,
and modes from
p
ython. However, we advice to use the UI instead.
It is also possible to create component, value and modes from
P
ython. However, we advice to use the UI instead.
```
python
# from nanospace import Nanospace
# nanospace = Nanospace('http://
yourSrvUrl/','yourU
sername', '
yourP
assword')
# nanospace = Nanospace('http://
server_address/','u
sername', '
p
assword')
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.
If the id is missing, check the Nanospace front-end url or the #id, that 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
p
ython.
Even if it is advise to delete element from the UI
, the following functions
give also the possibilities to delete element from
P
ython.
```
python
# from nanospace import Nanospace
# nanospace = Nanospace('http://
yourSrvUrl/','yourU
sername', '
yourP
assword')
# nanospace = Nanospace('http://
server_address/','u
sername', '
p
assword')
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
Note that __delete_value__ is working either if the value is a formula, or a string
.
## Bash client
...
...
This diff is collapsed.
Click to expand it.
auth_test.py
0 → 100644
+
38
−
0
View file @
19556750
import
requests
def
login_to_api
(
username
,
password
):
"""
Logs in to the API using the provided username and password.
Parameters:
username (str): The username for login.
password (str): The password for login.
Returns:
dict: A dictionary containing the API response, including the status code and response text.
"""
# Login API URL
url
=
'
http://localhost:8888/login
'
# Login data
data
=
{
'
username
'
:
username
,
'
password
'
:
password
}
response
=
requests
.
post
(
url
,
json
=
data
)
# Check response status
if
response
.
status_code
==
200
:
print
(
"
Login successful!
"
)
return
response
else
:
print
(
f
"
Login error:
{
response
.
status_code
}
"
)
return
{
'
error
'
:
response
.
text
,
'
status_code
'
:
response
.
status_code
}
# Example usage
if
__name__
==
"
__main__
"
:
result
=
login_to_api
(
'
test
'
,
'
test
'
)
print
(
result
)
This diff is collapsed.
Click to expand it.
nanospace.py
+
192
−
291
View file @
19556750
This diff is collapsed.
Click to expand it.
simple_example.py
+
85
−
16
View file @
19556750
from
nanospace
import
Nanospace
usr
=
'
usrLogin
'
pw
=
'
usrPw
'
srvAddr
=
'
https://dcas-nanostar.isae.fr/api/
'
nanospace
=
Nanospace
(
srvAddr
,
usr
,
pw
)
print
(
nanospace
.
get_string_value
(
5
))
# nanospace.update__string_value(83, 'test', '1Kg5')
# print(nanospace.get_formula_value(84))
# nanospace.update_formula_value(84, 'multiplication','5*20')
# nanospace._create_component(40, 'newComponent')
# nanospace._create_formula_value(231, 'test2', '5*5')
# nanospace._create_string_value(231, 'test3', 'Hello-world')
# nanospace._create_mode(60, 'new_mode')
# nanospace._delete_component(60)
# nanospace._delete_value(102)
# nanospace._delete_mode(231)
\ No newline at end of file
# ================================================================================
# ================================================================================
username
=
'
test
'
password
=
'
test
'
server
=
'
http://localhost:8888/
'
id
=
278
# For test : be sure this value exists
# ================================================================================
# ================================================================================
# Connection
nanospace
=
Nanospace
(
server
,
username
,
password
)
# ================================================================================
# ================================================================================
# Get a value
print
(
"
--------------------------------------------
"
)
print
(
nanospace
.
get_string_value
(
id
))
# ================================================================================
# ================================================================================
# Update the value and associated verification
nanospace
.
update_string_value
(
id
,
'
Earth_Radius
'
,
'
6378000
'
)
print
(
"
--------------------------------------------
"
)
print
(
nanospace
.
get_string_value
(
id
))
# ================================================================================
# ================================================================================
print
(
"
--------------------------------------------
"
)
print
(
nanospace
.
_delete_value
(
393
))
# ================================================================================
# ================================================================================
print
(
"
--------------------------------------------
"
)
print
(
nanospace
.
_create_string_value
(
44
,
'
test3
'
,
'
Hello-world
'
))
# ================================================================================
# ================================================================================
print
(
"
--------------------------------------------
"
)
print
(
nanospace
.
get_formula_value
(
444
))
nanospace
.
update_formula_value
(
444
,
'
multiplication
'
,
'
5*20
'
)
print
(
nanospace
.
get_formula_value
(
444
))
# ================================================================================
# ================================================================================
print
(
"
--------------------------------------------
"
)
nanospace
.
_create_component
(
85
,
'
newComponent
'
)
# ================================================================================
# ================================================================================
print
(
"
--------------------------------------------
"
)
nanospace
.
_create_formula_value
(
73
,
'
test1
'
,
'
5*5
'
)
# ================================================================================
# ================================================================================
print
(
"
--------------------------------------------
"
)
nanospace
.
_create_string_value
(
73
,
'
test2
'
,
'
Hello-world
'
)
# ================================================================================
# ================================================================================
print
(
"
--------------------------------------------
"
)
nanospace
.
_create_mode
(
23
,
'
new_mode_tutu
'
)
# ================================================================================
# ================================================================================
print
(
"
--------------------------------------------
"
)
nanospace
.
_delete_component
(
448
)
# ================================================================================
# ================================================================================
print
(
"
--------------------------------------------
"
)
nanospace
.
_delete_mode
(
449
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment