|
| 1 | +Tutorials |
| 2 | +==================== |
| 3 | + |
| 4 | +.. warning:: |
| 5 | + |
| 6 | + This is a work in progress, some features may change and packages may move or be removed |
| 7 | + before the 1.0 release. |
| 8 | + |
| 9 | +Using the API |
| 10 | +============================ |
| 11 | +There are three main ways to interact with the API |
| 12 | + |
| 13 | +1. Direct API calls |
| 14 | +----------------------------------------- |
| 15 | +In the modules for parts 1 and 2, there are separate files that represent the different parts of the API. These files |
| 16 | +contain methods for interacting with the remote server directly. |
| 17 | + |
| 18 | +2. Default API Helper |
| 19 | +----------------------------------------- |
| 20 | +Using the Default API helper allows for repeated calls to the same API server. This is useful when |
| 21 | +building a library on top of this project. |
| 22 | + |
| 23 | +3. Custom API Requests |
| 24 | +----------------------------------------- |
| 25 | +If you need the most flexibility, you can create custom requests using the request builder and API helper objects |
| 26 | + |
| 27 | +Interacting with Systems |
| 28 | +============================ |
| 29 | + |
| 30 | +List Systems |
| 31 | +----------------------------------------- |
| 32 | +.. note:: |
| 33 | + |
| 34 | + Using a direct call from `Systems` file |
| 35 | +.. code-block:: python |
| 36 | +
|
| 37 | + from consys4py import Systems |
| 38 | +
|
| 39 | + Systems.list_all_systems(server_url) |
| 40 | +
|
| 41 | +Retrieve Specific System |
| 42 | +----------------------------------------- |
| 43 | + |
| 44 | +.. code-block:: python |
| 45 | +
|
| 46 | + from consys4py import Systems |
| 47 | +
|
| 48 | + Systems.retrieve_system_by_id(server_url, system_id) |
| 49 | +
|
| 50 | +Add/Create System |
| 51 | +----------------------------------------- |
| 52 | +The method for creating a new system does take a string or properly structured `dict`. |
| 53 | +For ease of use, the `SmlJSONBody` or `GeoJSONBody` can be used. They use Pydantic to validate the data. |
| 54 | +Just be sure to convert them to a JSON string before passing them to the `create_new_systems` method. |
| 55 | + |
| 56 | +.. code-block:: python |
| 57 | +
|
| 58 | + from consys4py import Systems |
| 59 | +
|
| 60 | + sml = SmlJSONBody(object_type='SimpleProcess', id=str(random.randint(1000, 9999)), |
| 61 | + description="A Test System inserted from the Python Connected Systems API Client", |
| 62 | + unique_id=f'urn:test:client:sml-single', label=f'Test System - SML Single', |
| 63 | + definition="http://test.com") |
| 64 | +
|
| 65 | + sml_as_str = sml.model_dump_json(exclude_none=True, by_alias=True) |
| 66 | + Systems.create_new_systems(server_url, sml_as_str, uname="test", pword="test", |
| 67 | + headers=sml_json_headers) |
0 commit comments