Skip to content

Commit 7bb184f

Browse files
committed
feat: extract examples in separate files
1 parent 5a9b137 commit 7bb184f

File tree

6 files changed

+73
-44
lines changed

6 files changed

+73
-44
lines changed

README.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ you're testing the API or building production workflows, these scripts will help
2121

2222
```bash
2323
easyssp-import-export-examples-python/
24-
├── demo.py # Run a basic scenario
24+
├── demo_config.py # User agent and easySSP username and password config.
25+
├── ssd_import_demo.py # Run a .ssd file import demo.
26+
├── ssp_export_demo.py # Run a .ssp file export demo.
27+
├── ssp_import_demo.py # Run a .ssp file import demo.
2528
├── input/
2629
│ └── ssd_example.ssd # SSD file for importing
2730
│ └── ssp_example.ssp # SSP file for importing
@@ -67,8 +70,7 @@ uv sync
6770

6871
## 3. Provide your login credentials
6972

70-
In the `demo.py` file, replace `your_easyssp_username` and `your_easyssp_password` with your real easySSP credentials
71-
to start the demo.
73+
In the `demo_config.py` file, provide your easySSP credentials to start the demo.
7274

7375
---
7476

@@ -92,18 +94,20 @@ This separation of input and output ensures clarity, reproducibility, and easy c
9294

9395
---
9496

95-
#### 🧪 `demo.py`
97+
#### 🧪 Demo
9698

97-
The `demo.py` script in the `demo` directory acts as a **central demo runner** and contains example requests that show
99+
The `ssd_import_demo.py`, `ssp_export_demo.py`, and `ssp_import_demo.py` scripts in the `demo` directory act as **central demo runners** and contain example requests that show
98100
how to use the client.
99-
It's a great starting point if you're exploring the API for the first time or want to see full workflows in action.
100-
To start the demo, run
101+
They're a great starting point if you're exploring the API for the first time or want to see full workflows in action.
102+
To start a demo, run
101103

102104
```bash
103105
cd demo
104-
python -m demo
106+
python -m demo_file
105107
```
106108

109+
Replace `demo_file` with one of the following: `ssd_import_demo`, `ssp_export_demo` or `ssp_import_demo`.
110+
107111
## 📚 Related Projects
108112

109113
### 🧠 [**Import/Export Client**](https://github.com/exxcellent/easyssp-import-export-client-python)

demo/demo.py

Lines changed: 0 additions & 36 deletions
This file was deleted.

demo/demo_config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
USER_AGENT = "easyssp-import-export-examples-python"
2+
EASYSSP_USERNAME = ""
3+
EASYSSP_PASSWORD = ""

demo/ssd_import_demo.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from easyssp_auth import AuthError
2+
from easyssp_import_export.client.import_export_client import ImportExportClient
3+
from easyssp_utils.client import ApiException
4+
from pydantic import ValidationError
5+
from demo_config import USER_AGENT, EASYSSP_USERNAME, EASYSSP_PASSWORD
6+
7+
with (open("../input/ssd_example.ssd", "rb") as ssd_input_file):
8+
try:
9+
import_export_client = ImportExportClient(username=EASYSSP_USERNAME, password=EASYSSP_PASSWORD,
10+
user_agent=USER_AGENT)
11+
# import a .ssd file
12+
ssd_import_result = import_export_client.import_ssd(filename="ssd_import_example.ssd",
13+
body=ssd_input_file.read())
14+
print(ssd_import_result.data)
15+
# catch ValidationError for incorrect request parameters
16+
# catch ApiException for errors from the API client or the server
17+
except (AuthError, ApiException, ValidationError) as ex:
18+
print(ex)

demo/ssp_export_demo.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from easyssp_auth import AuthError
2+
from easyssp_import_export.client.import_export_client import ImportExportClient
3+
from easyssp_utils.client import ApiException
4+
from pydantic import ValidationError
5+
from demo_config import USER_AGENT, EASYSSP_USERNAME, EASYSSP_PASSWORD
6+
7+
with (open("../output/ssp_output.ssp", "wb") as ssp_output_file):
8+
try:
9+
import_export_client = ImportExportClient(username=EASYSSP_USERNAME, password=EASYSSP_PASSWORD,
10+
user_agent=USER_AGENT)
11+
# get the SSP model id from the console
12+
ssp_id = input("Enter SSP model id: ")
13+
14+
# export it to .ssp file
15+
ssp_export_result = import_export_client.export_ssp(ssp_id=ssp_id)
16+
ssp_output_file.write(ssp_export_result.data) # write the exported file to the file system
17+
print("The SSP model has been successfully exported.")
18+
# catch ValidationError for incorrect request parameters
19+
# catch ApiException for errors from the API client or the server
20+
except (AuthError, ApiException, ValidationError) as ex:
21+
print(ex)

demo/ssp_import_demo.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from easyssp_auth import AuthError
2+
from easyssp_import_export.client.import_export_client import ImportExportClient
3+
from easyssp_utils.client import ApiException
4+
from pydantic import ValidationError
5+
from demo_config import USER_AGENT, EASYSSP_USERNAME, EASYSSP_PASSWORD
6+
7+
with (open("../input/ssp_example.ssp", "rb") as ssp_input_file):
8+
try:
9+
import_export_client = ImportExportClient(username=EASYSSP_USERNAME, password=EASYSSP_PASSWORD,
10+
user_agent=USER_AGENT)
11+
12+
# import a .ssp file
13+
ssp_import_result = import_export_client.import_ssp(filename="ssp_import_example.ssp",
14+
body=ssp_input_file.read())
15+
print(ssp_import_result.data)
16+
# catch ValidationError for incorrect request parameters
17+
# catch ApiException for errors from the API client or the server
18+
except (AuthError, ApiException, ValidationError) as ex:
19+
print(ex)

0 commit comments

Comments
 (0)