CoreConnect - Python helper class to communicate with InoCore
This PIP package provides the CoreConnect class to easily communicate with an InoCore installation.
Requirements
- Python 3.8 or newer
Installation
Make sure your PIP is up-to-date:
python -m install --upgrade pip
To install it:
python -m pip install core_connect
Usage
Basic
The usage is pretty straight forward. Make sure to import the class:
>>> from core_connect import CoreConnect
Now you can create a CoreConnect object with the InoCore URL, your InoCore credentials and the current project id:
>>> cc = CoreConnect(url, username, password, project_id)
With that you can easily make InoCore API request with the according HTTP method. The methods will return the deserialized content of the response body. For example:
>>> cc.get('v1/ping')
{'data': {'PONG': 1691587400.685406}, 'statusCode': 200}
# data has to be a JSON-serializable object like a dict or a list.
>>> data = {
'project_id': 'nice_project',
'bus_type': 'MODBUS',
'hostname': '192.168.1.2',
'port': 502,
'name': 'high end DDC'
}
>>> cc.post('v1/bus_config', data=data)
{
'data': {
'object': {
'bus_type': 'MODBUS',
'hostname': '192.168.1.2',
'id': 160,
'is_offline': False,
'name': 'high end DDC',
'node_id': -1,
'packet_size': 0,
'port': 502,
'project_id': 'nice_project',
'protocol': 'tcp',
'ref_user_id': 1,
'status': 1
},
'status': 'OK'
},
'statusCode': 200
}
Per default the methods will return the deserialized content of the response body on success. On failure an Exception will be raised. The kind of Exception raised can give a hint where the error might have happened:
InvalidUrlException:The InoCore URL or the URL resulting from adding the endpoint in a call is not valid.AuthorizationError:You provided wrong credentials or your user does not have access on specified API endpoint.InvalidResponseException:The client received an invalid response from InoCore. That might be the case when we received malformed JSON for example, but also more commonly when we received a response with a HTTP status code that is not 2xx. In that case the HTTP status code will be printed as well as the error message from InoCore if there is any.
Advanced
Response object
Instead of returning the deserialized response body, you can also receive the whole requests.Response object from the call. That gives you more flexibility. To do so, you just need to set the parameter return_object=True when initializing the CoreConnect object.
Self-signed TLS
You can also allow connections to InoCore instances that use self-signed TLS certificates. To do that you just need to set the parameter verify_peer=False when initializing the CoreConnect object. ONLY do that if you are in a secure network and you know what you are doing!
Class methods
The following methods are implemented:
get(endpoint, params=None)
post(endpoint, data=None, params=None)
put(endpoint, data=None, params=None)
delete(endpoint, data=None, params=None)
Whereas data has to be JSON-serializable. For filtering, sorting limiting and using offset you can use params in that form:
params = {
'filter': [
{'property': 'project_id', 'expression': 'ilike', 'value': 'nice_project'},
{'property': 'project_id', 'expression': 'ilike', 'value': 'nice_project_2'},
],
'sort': [
{'property': 'id', 'direction': 'asc'},
{'property': 'name', 'direction': 'desc'},
],
'limit': 10,
'offset': 5,
}
As you can see, you can filter and sort by multiple properties.
Metadata
Release files for core-connect 2.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| core_connect-2.1.1.tar.gz | 6.7 kB | Without provenance | Details for core_connect-2.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| core_connect-2.1.1-py3-none-any.whl | Python 3 | none | any | Details for core_connect-2.1.1-py3-none-any.whl |
Total release size: 13.7 kB
Release files / core_connect-2.1.1.tar.gz
| Download URL | core_connect-2.1.1.tar.gz |
|---|---|
| Size | 6.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3efa614fbbb233d34111d5012b3650ac6357f8403cb5754ca3b149edbd2d2080
|
|
BLAKE2b-256 checksum How to use checksums |
c54f93296b3adcaccca3019a50db17dcb1c93026b9a5230608f22817a839a5f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.15
|
Release files / core_connect-2.1.1-py3-none-any.whl
| Download URL | core_connect-2.1.1-py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d09c09cf9b545c5b80c75b9b3b86262f6b136d2ce77637eca3bae1c397d3d7c9
|
|
BLAKE2b-256 checksum How to use checksums |
3ae1fa1539dbc3155cba3289fd5e467db29b8071832994aba228a4aabe71505e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.15
|
Security for core-connect 2.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.