Skip to content

Commit 002e103

Browse files
author
KepwareSalesAE
authored
Merge pull request #1 from PTCInc/Beta3
Beta3
2 parents 7843881 + 7b07db2 commit 002e103

25 files changed

Lines changed: 2889 additions & 26 deletions

LICENSE

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
MIT License
22

3-
4-
Copyright (c) 2020, PTC Inc. and/or all its affiliates. All rights reserved.
3+
Copyright (c) PTC Inc. and/or all its affiliates. All rights reserved.
54

65
Permission is hereby granted, free of charge, to any person obtaining a copy
76
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Kepware Configuration API SDK for Python
22

3-
This is a package SDK to create Python modules to conduct operations with the Kepware Configuration API.
3+
This is a package SDK to create Python modules to conduct operations with the Kepware Configuration API. THis package is designed to work with all versions of Kepware that support the Configuration API including Thingworx Kepware Server (TKS), Thingworx Kepware Edge (TKE) and KEPServerEX (KEP).
44

55
## Prerequisites
66

@@ -12,24 +12,38 @@ The client libraries are supported on Python 3.6 or later. All HTTP communicatio
1212

1313
SDK allows for *GET*, *ADD*, *DELETE*, and *MODIFY* functions for the following Kepware configuration objects:
1414

15-
- **Project Properties** *(Get and Modify Only)*
16-
- **Connectivity** *(Channel, Devices, Tags, Tag Groups)*
17-
- **IoT Gateway** *(Agents, IoT Items)*
15+
| Features | TKS/KEP | TKE |
16+
| :----------: | :----------: | :----------: |
17+
| **Project Properties** <br /> *(Get and Modify Only)* | Y | Y |
18+
| **Connectivity** <br /> *(Channel, Devices, Tags, Tag Groups)* | Y | Y |
19+
| **IoT Gateway** <br /> *(Agents, IoT Items)* | Y | Y |
20+
| **Datalogger** <br /> *(Log Groups, Items, Mapping, Triggers, Reset Mapping Service)* | Y | Y |
21+
| **Administration** <br /> *(User Groups, Users, UA Endpoints)* | Y* | Y |
22+
23+
Note (*) - UA Endpoints supported for Kepware Edge only
1824

1925
Methods to read the following logs:
2026

21-
- **Event Log**
22-
- **API Transaction Log**
27+
| Logs | TKS/KEP | TKE |
28+
| :----------: | :----------: | :----------: |
29+
| **Event Log** | Y | Y |
30+
| **API Transaction Log** | Y | Y |
31+
32+
Configuration API *Services* implemented:
33+
34+
| Services | TKS/KEP | TKE |
35+
| :----------: | :----------: | :----------: |
36+
| **TagGeneration** <br /> *(not supported by all drivers)* | Y | Y |
37+
| **ReinitializeRuntime** | Y* | Y |
2338

24-
Additionally the following *Services* are implemented:
39+
Note (*) - Reinitialize service was implemented for Kepware Server v6.8+
2540

26-
- **TagGeneration** *(not supported by all drivers)*
27-
- **ReinitializeRuntime** *(Thingworx Kepware Edge and Kepware Server 6.8+)*
41+
Generic REST methods are provided to use for functions not developed in SDK package. These are found in the Server Class in [connection.py](/kepconfig/connection.py)
2842

2943
## Known Limitations
3044

3145
- Other property configruation for more complex drivers are not explicitly defined
32-
- Other supported plug-ins (Datalogger, Scheduler, etc) are not defined
46+
- Other supported plug-ins (EFM Exporter, Scheduler, etc) are not defined
3347
- When using hostnames (not IP addresses) for connections, delays may occur under certain network configurations as the connection may attempt IPv6 connections first. IPv6 is not supported by Kepware servers at this time.
3448

3549
## Installation
@@ -42,6 +56,8 @@ pip install kepconfig-<version>-py3-none-any.whl -f ./ --no-index
4256

4357
## Key Concepts
4458

59+
NOTE: Samples can also be found in the [samples](samples) folder.
60+
4561
### Create server connection
4662

4763
```python
@@ -54,7 +70,7 @@ server = connection.server(host = '127.0.0.1', port = 57412, user = 'Administrat
5470

5571
```
5672

57-
For certificate validation, the SDK uses the OS/systems trusted CA certificate store. The connection leverages uses the "create_default_context()" function as part of urllib as described at the following links:
73+
For certificate validation, the SDK uses the OS/systems trusted CA certificate store. The connection uses the "create_default_context()" function as part of urllib as described at the following links:
5874

5975
- [ssl.create_default_context](https://docs.python.org/3/library/ssl.html#ssl.create_default_context)
6076
- [ssl.SSLContext.load_default_certs](https://docs.python.org/3/library/ssl.html#ssl.SSLContext.load_default_certs)
@@ -64,7 +80,7 @@ For Windows OSes, the Kepware server's instance certificate can be loaded into t
6480

6581
### Create an object
6682

67-
Objects such as channels or devices can be created either sigularly or with children included.
83+
Objects such as channels or devices can be created either singularly or with children included.
6884

6985
### Ex: Add Single channel
7086

@@ -98,5 +114,7 @@ result = tag.add_tag(server, tag_path, tag_info))
98114
## Need More Information
99115

100116
**Visit:**
101-
- [Kepware.com](https://www.kepware.com/)
102-
- [Configuration API Info](https://www.kepware.com/en-us/products/kepserverex/features/configuration-api/)
117+
118+
[Kepware.com](https://www.kepware.com/)
119+
[Configuration API Info](https://www.kepware.com/en-us/products/kepserverex/features/configuration-api/)
120+
[PTC.com](https://www.ptc.com/)
30.2 KB
Binary file not shown.

dist/kepconfig-1.0b3.tar.gz

20.2 KB
Binary file not shown.

kepconfig/admin/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# -------------------------------------------------------------------------
2+
# Copyright (c) 2020, PTC Inc. and/or all its affiliates. All rights reserved.
3+
# See License.txt in the project root for
4+
# license information.
5+
# --------------------------------------------------------------------------
6+
7+
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
8+
from . import users, user_groups,ua_server

kepconfig/admin/ua_server.py

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# -------------------------------------------------------------------------
2+
# Copyright (c), PTC Inc. and/or all its affiliates. All rights reserved.
3+
# See License.txt in the project root for
4+
# license information.
5+
# --------------------------------------------------------------------------
6+
7+
r""":mod:`ua_server` exposes an API to allow modifications (add, delete, modify) to
8+
OPC UA Server endpoints within the Kepware Administration through the Kepware Configuration API
9+
"""
10+
UA_ROOT = '/admin/ua_endpoints'
11+
12+
def _create_url(endpoint = None):
13+
'''Creates url object for the "server_users" branch of Kepware's project tree. Used
14+
to build a part of Kepware Configuration API URL structure
15+
16+
Returns the user specific url when a value is passed as the user name.
17+
'''
18+
19+
if endpoint == None:
20+
return UA_ROOT
21+
else:
22+
return '{}/{}'.format(UA_ROOT,endpoint)
23+
24+
def add_endpoint(server, DATA):
25+
'''Add an "endpoint" or multiple "endpoint" objects to Kepware UA Server by passing a
26+
list of endpoints to be added all at once.
27+
28+
INPUTS:
29+
"server" - instance of the "server" class
30+
31+
"DATA" - properly JSON object (dict) of the endpoint
32+
expected by Kepware Configuration API
33+
34+
RETURNS:
35+
True - If a "HTTP 201 - Created" is received from Kepware
36+
37+
EXCEPTIONS:
38+
KepHTTPError - If urllib provides an HTTPError
39+
KepURLError - If urllib provides an URLError
40+
'''
41+
42+
r = server._config_add(server.url + _create_url(), DATA)
43+
if r.code == 201: return True
44+
else: return False
45+
46+
def del_endpoint(server, endpoint):
47+
'''Delete a "endpoint" object in Kepware UA Server
48+
49+
INPUTS:
50+
"server" - instance of the "server" class
51+
52+
"endpoint" - name of endpoint
53+
54+
RETURNS:
55+
True - If a "HTTP 200 - OK" is received from Kepware
56+
57+
EXCEPTIONS:
58+
KepHTTPError - If urllib provides an HTTPError
59+
KepURLError - If urllib provides an URLError
60+
'''
61+
62+
r = server._config_del(server.url + _create_url(endpoint))
63+
if r.code == 200: return True
64+
else: return False
65+
66+
def modify_endpoint(server, DATA, endpoint = None):
67+
'''Modify a endpoint object and it's properties in Kepware UA Server. If a "endpoint" is not provided as an input,
68+
you need to identify the endpoint in the 'common.ALLTYPES_NAME' property field in the "DATA". It will
69+
assume that is the endpoint that is to be modified.
70+
71+
INPUTS:
72+
"server" - instance of the "server" class
73+
74+
"DATA" - properly JSON object (dict) of the endpoint properties to be modified.
75+
76+
"endpoint" (optional) - name of endpoint to modify. Only needed if not existing in "DATA"
77+
78+
RETURNS:
79+
True - If a "HTTP 200 - OK" is received from Kepware
80+
81+
EXCEPTIONS:
82+
KepHTTPError - If urllib provides an HTTPError
83+
KepURLError - If urllib provides an URLError
84+
'''
85+
86+
# channel_data = server._force_update_check(force, DATA)
87+
if endpoint == None:
88+
try:
89+
r = server._config_update(server.url + _create_url(DATA['common.ALLTYPES_NAME']), DATA)
90+
if r.code == 200: return True
91+
else: return False
92+
except KeyError as err:
93+
print('Error: No UA Endpoint identified in DATA | Key Error: {}'.format(err))
94+
return False
95+
# except Exception as e:
96+
# return 'Error: Error with {}: {}'.format(inspect.currentframe().f_code.co_name, str(e))
97+
else:
98+
r = server._config_update(server.url + _create_url(endpoint), DATA)
99+
if r.code == 200: return True
100+
else: return False
101+
102+
def get_endpoint(server, endpoint):
103+
'''Returns the properties of the endpoint object. Returned object is JSON.
104+
105+
INPUTS:
106+
"server" - instance of the "server" class
107+
108+
"endpoint" - name of endpoint
109+
110+
RETURNS:
111+
JSON - data for the endpoint requested
112+
113+
EXCEPTIONS:
114+
KepHTTPError - If urllib provides an HTTPError
115+
KepURLError - If urllib provides an URLError
116+
'''
117+
118+
r = server._config_get(server.url + _create_url(endpoint))
119+
return r.payload
120+
121+
def get_all_endpoints(server):
122+
'''Returns list of all endpoint objects and their properties. Returned object is JSON list.
123+
124+
INPUTS:
125+
"server" - instance of the "server" class
126+
127+
RETURNS:
128+
JSON - data for all endpoints requested
129+
130+
EXCEPTIONS:
131+
KepHTTPError - If urllib provides an HTTPError
132+
KepURLError - If urllib provides an URLError
133+
'''
134+
135+
r = server._config_get(server.url + _create_url())
136+
return r.payload

0 commit comments

Comments
 (0)