industrial-connect 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. industrial_connect-0.1.0/LICENSE +202 -0
  2. industrial_connect-0.1.0/MANIFEST.in +8 -0
  3. industrial_connect-0.1.0/PKG-INFO +121 -0
  4. industrial_connect-0.1.0/README.md +83 -0
  5. industrial_connect-0.1.0/docs/configuration.md +51 -0
  6. industrial_connect-0.1.0/docs/databases.md +89 -0
  7. industrial_connect-0.1.0/docs/graylog.md +25 -0
  8. industrial_connect-0.1.0/docs/logging.md +93 -0
  9. industrial_connect-0.1.0/docs/mqtt.md +140 -0
  10. industrial_connect-0.1.0/docs/mssql.md +29 -0
  11. industrial_connect-0.1.0/docs/opcua.md +118 -0
  12. industrial_connect-0.1.0/docs/operations.md +62 -0
  13. industrial_connect-0.1.0/docs/oracle.md +34 -0
  14. industrial_connect-0.1.0/docs/postgres.md +27 -0
  15. industrial_connect-0.1.0/docs/publishing.md +45 -0
  16. industrial_connect-0.1.0/docs/questdb.md +73 -0
  17. industrial_connect-0.1.0/docs/sqlite.md +31 -0
  18. industrial_connect-0.1.0/examples/.env.example +47 -0
  19. industrial_connect-0.1.0/examples/README.md +93 -0
  20. industrial_connect-0.1.0/examples/__init__.py +1 -0
  21. industrial_connect-0.1.0/examples/_common.py +45 -0
  22. industrial_connect-0.1.0/examples/databases.py +19 -0
  23. industrial_connect-0.1.0/examples/env_config.py +22 -0
  24. industrial_connect-0.1.0/examples/graylog.py +30 -0
  25. industrial_connect-0.1.0/examples/logging_setup.py +29 -0
  26. industrial_connect-0.1.0/examples/mqtt.py +89 -0
  27. industrial_connect-0.1.0/examples/mqtt_callback.py +40 -0
  28. industrial_connect-0.1.0/examples/mssql.py +38 -0
  29. industrial_connect-0.1.0/examples/opcua.py +51 -0
  30. industrial_connect-0.1.0/examples/oracle.py +43 -0
  31. industrial_connect-0.1.0/examples/oracle_plsql.py +22 -0
  32. industrial_connect-0.1.0/examples/postgres.py +37 -0
  33. industrial_connect-0.1.0/examples/questdb.py +47 -0
  34. industrial_connect-0.1.0/examples/shared_client/__init__.py +0 -0
  35. industrial_connect-0.1.0/examples/shared_client/http_handlers.py +11 -0
  36. industrial_connect-0.1.0/examples/shared_client/main.py +17 -0
  37. industrial_connect-0.1.0/examples/shared_client/mqtt_callbacks.py +17 -0
  38. industrial_connect-0.1.0/examples/shared_client/mqtt_main.py +42 -0
  39. industrial_connect-0.1.0/examples/shared_client/named_main.py +27 -0
  40. industrial_connect-0.1.0/examples/shared_client/report.py +5 -0
  41. industrial_connect-0.1.0/examples/shared_client/repository.py +5 -0
  42. industrial_connect-0.1.0/examples/sqlite.py +37 -0
  43. industrial_connect-0.1.0/manage.py +163 -0
  44. industrial_connect-0.1.0/pyproject.toml +46 -0
  45. industrial_connect-0.1.0/setup.cfg +4 -0
  46. industrial_connect-0.1.0/src/industrial_connect/__init__.py +10 -0
  47. industrial_connect-0.1.0/src/industrial_connect/_notifications.py +26 -0
  48. industrial_connect-0.1.0/src/industrial_connect/_optional.py +13 -0
  49. industrial_connect-0.1.0/src/industrial_connect/config.py +89 -0
  50. industrial_connect-0.1.0/src/industrial_connect/db/__init__.py +31 -0
  51. industrial_connect-0.1.0/src/industrial_connect/db/_base.py +151 -0
  52. industrial_connect-0.1.0/src/industrial_connect/db/mssql.py +54 -0
  53. industrial_connect-0.1.0/src/industrial_connect/db/oracle.py +176 -0
  54. industrial_connect-0.1.0/src/industrial_connect/db/postgres.py +142 -0
  55. industrial_connect-0.1.0/src/industrial_connect/db/questdb.py +166 -0
  56. industrial_connect-0.1.0/src/industrial_connect/db/registry.py +66 -0
  57. industrial_connect-0.1.0/src/industrial_connect/db/sqlite.py +86 -0
  58. industrial_connect-0.1.0/src/industrial_connect/db/types.py +7 -0
  59. industrial_connect-0.1.0/src/industrial_connect/errors.py +34 -0
  60. industrial_connect-0.1.0/src/industrial_connect/logging.py +94 -0
  61. industrial_connect-0.1.0/src/industrial_connect/mqtt.py +337 -0
  62. industrial_connect-0.1.0/src/industrial_connect/opcua.py +537 -0
  63. industrial_connect-0.1.0/src/industrial_connect/py.typed +0 -0
  64. industrial_connect-0.1.0/src/industrial_connect.egg-info/PKG-INFO +121 -0
  65. industrial_connect-0.1.0/src/industrial_connect.egg-info/SOURCES.txt +91 -0
  66. industrial_connect-0.1.0/src/industrial_connect.egg-info/dependency_links.txt +1 -0
  67. industrial_connect-0.1.0/src/industrial_connect.egg-info/requires.txt +40 -0
  68. industrial_connect-0.1.0/src/industrial_connect.egg-info/top_level.txt +1 -0
  69. industrial_connect-0.1.0/tests/integration/README.md +41 -0
  70. industrial_connect-0.1.0/tests/integration/compose.yaml +45 -0
  71. industrial_connect-0.1.0/tests/integration/conftest.py +21 -0
  72. industrial_connect-0.1.0/tests/integration/mosquitto.conf +3 -0
  73. industrial_connect-0.1.0/tests/integration/test_opcua_service.py +162 -0
  74. industrial_connect-0.1.0/tests/integration/test_services.py +138 -0
  75. industrial_connect-0.1.0/tests/test_connector_examples.py +103 -0
  76. industrial_connect-0.1.0/tests/test_core.py +96 -0
  77. industrial_connect-0.1.0/tests/test_database_registry.py +187 -0
  78. industrial_connect-0.1.0/tests/test_databases.py +242 -0
  79. industrial_connect-0.1.0/tests/test_env_config.py +197 -0
  80. industrial_connect-0.1.0/tests/test_logging.py +110 -0
  81. industrial_connect-0.1.0/tests/test_manage.py +213 -0
  82. industrial_connect-0.1.0/tests/test_mqtt.py +239 -0
  83. industrial_connect-0.1.0/tests/test_mqtt_callbacks.py +196 -0
  84. industrial_connect-0.1.0/tests/test_mqtt_pipeline.py +75 -0
  85. industrial_connect-0.1.0/tests/test_opcua.py +354 -0
  86. industrial_connect-0.1.0/tests/test_opcua_certificates.py +118 -0
  87. industrial_connect-0.1.0/tests/test_oracle.py +91 -0
  88. industrial_connect-0.1.0/tests/test_production_failures.py +185 -0
  89. industrial_connect-0.1.0/tests/test_questdb.py +257 -0
  90. industrial_connect-0.1.0/tests/test_shared_client_example.py +42 -0
  91. industrial_connect-0.1.0/tests/typing/db_usage.py +80 -0
  92. industrial_connect-0.1.0/tools/check_extras.py +44 -0
  93. industrial_connect-0.1.0/tools/check_install.py +69 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Kristjan Cuznar
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,8 @@
1
+ include README.md LICENSE pyproject.toml
2
+ recursive-include docs *.md
3
+ include manage.py
4
+ recursive-include examples *.py *.md
5
+ include examples/.env.example
6
+ recursive-include tests *.py *.md *.yaml *.conf
7
+ recursive-include tools *.py
8
+ exclude dev.py
@@ -0,0 +1,121 @@
1
+ Metadata-Version: 2.4
2
+ Name: industrial-connect
3
+ Version: 0.1.0
4
+ Summary: Small, independently usable industrial Python connectors
5
+ License-Expression: Apache-2.0
6
+ Requires-Python: >=3.12
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Provides-Extra: env
10
+ Requires-Dist: python-dotenv<2,>=1.2.4; extra == "env"
11
+ Provides-Extra: postgres
12
+ Requires-Dist: psycopg[binary]<4,>=3.3.6; extra == "postgres"
13
+ Requires-Dist: psycopg-pool<4,>=3.3.3; extra == "postgres"
14
+ Provides-Extra: oracle
15
+ Requires-Dist: oracledb<27,>=26.0.1; extra == "oracle"
16
+ Provides-Extra: mssql
17
+ Requires-Dist: pymssql<3,>=2.4.5; extra == "mssql"
18
+ Provides-Extra: questdb
19
+ Requires-Dist: questdb<7,>=6.0; extra == "questdb"
20
+ Provides-Extra: sqlite
21
+ Provides-Extra: opcua
22
+ Requires-Dist: asyncua<3,>=2.1; extra == "opcua"
23
+ Provides-Extra: mqtt
24
+ Requires-Dist: paho-mqtt<3,>=2.1; extra == "mqtt"
25
+ Provides-Extra: graylog
26
+ Requires-Dist: graypy<3,>=2.1; extra == "graylog"
27
+ Provides-Extra: db
28
+ Requires-Dist: industrial-connect[mssql,oracle,postgres,questdb,sqlite]==0.1.0; extra == "db"
29
+ Provides-Extra: all
30
+ Requires-Dist: industrial-connect[db,env,graylog,mqtt,opcua]==0.1.0; extra == "all"
31
+ Provides-Extra: dev
32
+ Requires-Dist: pytest<10,>=8.3; extra == "dev"
33
+ Requires-Dist: build<2,>=1.2; extra == "dev"
34
+ Requires-Dist: twine<7,>=6; extra == "dev"
35
+ Requires-Dist: ruff<1,>=0.14; extra == "dev"
36
+ Requires-Dist: pyright<2,>=1.1.414; extra == "dev"
37
+ Dynamic: license-file
38
+
39
+ # industrial-connect
40
+
41
+ Reusable Python connectors for industrial applications. Python 3.12+, Windows and Linux.
42
+ Optional drivers, explicit resource ownership, no import-time connections.
43
+
44
+ ## Install
45
+
46
+ ```shell
47
+ pip install industrial-connect # SQLite and core
48
+ pip install "industrial-connect[postgres,env]"
49
+ pip install "industrial-connect[mqtt,opcua]"
50
+ pip install "industrial-connect[all]"
51
+ ```
52
+
53
+ Install only the drivers you need. Pin the tested library version and lock your
54
+ application's dependencies. `db` includes every database; `all` includes every extra.
55
+
56
+ ## Connectors and runnable examples
57
+
58
+ Each guide includes configuration, a realistic example, resource lifetime and error behavior.
59
+ Run examples from the checkout; `--help` lists the available options.
60
+
61
+ | Connector | Extra | Guide | Example |
62
+ | --- | --- | --- | --- |
63
+ | PostgreSQL | `postgres` | [PostgreSQL](docs/postgres.md) | `python -m examples.postgres` |
64
+ | Oracle | `oracle` | [Oracle and PL/SQL](docs/oracle.md) | `python -m examples.oracle` |
65
+ | SQL Server | `mssql` | [SQL Server](docs/mssql.md) | `python -m examples.mssql` |
66
+ | SQLite | none | [SQLite](docs/sqlite.md) | `python -m examples.sqlite` |
67
+ | QuestDB QWP | `questdb` | [WebSocket ingestion and SQL](docs/questdb.md) | `python -m examples.questdb` |
68
+ | MQTT | `mqtt` | [Queue or callback telemetry](docs/mqtt.md) | `python -m examples.mqtt` / `examples.mqtt_callback` |
69
+ | OPC UA | `opcua` | [PLC reads, writes and subscriptions](docs/opcua.md) | `python -m examples.opcua` |
70
+ | Console/files | none | [Logging](docs/logging.md) | `python -m examples.logging_setup` |
71
+ | Graylog | `graylog` | [GELF/UDP](docs/graylog.md) | `python -m examples.graylog` |
72
+
73
+ ## Quick start without a service
74
+
75
+ ```python
76
+ from industrial_connect.db import SqliteClient, SqliteConfig
77
+
78
+ with SqliteClient(SqliteConfig(database=":memory:")) as db:
79
+ db.execute("CREATE TABLE readings(equipment TEXT, temperature_c REAL)")
80
+ with db.transaction() as tx:
81
+ tx.execute("INSERT INTO readings VALUES (?, ?)", ("MILL_1", 72.5))
82
+ print(db.query("SELECT * FROM readings WHERE equipment=?", ("MILL_1",)))
83
+ ```
84
+
85
+ Every config supports explicit constructors and `from_env()`; loading a `.env` file
86
+ requires the `env` extra and an explicit `env_file` argument. See
87
+ [configuration](docs/configuration.md) and the [sample environment](examples/.env.example).
88
+ For persistent clients shared across modules, see [the sharing guide](examples/README.md).
89
+
90
+ ## Operational contracts
91
+
92
+ - Close clients after workers stop. Context managers own cleanup; closing is terminal.
93
+ - Use bound SQL parameters. Native placeholders differ by database; see the guides.
94
+ - Catch `IndustrialConnectError` or its `DependencyError`, `ConnectionError` and
95
+ `OperationError` subclasses. Native errors remain in exception chains; cleanup
96
+ failures add notes instead of hiding the original failure.
97
+ - A failed write may already have arrived. The wrapper does not retry writes; native
98
+ MQTT and QuestDB drivers have their own delivery/reconnect behavior.
99
+ - MQTT/OPC UA queues are bounded. Monitor `dropped_count`; overflow means data loss.
100
+ - Configure logging once with `setup_logging()`; modules use `get_logger(__name__)`.
101
+ - Configure TLS, certificate trust and credentials for your deployment. Avoid logging
102
+ secrets and raw driver exception chains. Graylog GELF/UDP is unencrypted.
103
+
104
+ See [database contracts](docs/databases.md) and [deployment and verification](docs/operations.md).
105
+
106
+ ## Develop and publish
107
+
108
+ ```shell
109
+ python -m pip install -e ".[all,dev]"
110
+ python manage.py check
111
+ python manage.py build
112
+ ```
113
+
114
+ The build command runs checks and creates a wheel and source archive in `dist/`.
115
+ Uploads are explicit. See [publishing](docs/publishing.md) for version bumps,
116
+ TestPyPI, PyPI and private registries, and [integration tests](tests/integration/README.md)
117
+ for disposable services. Passing unit tests alone does not validate your plant's devices,
118
+ network, database permissions or delivery requirements.
119
+
120
+ Licensed under [Apache-2.0](LICENSE). SQLite defaults to `store.db`;
121
+ `SqliteConfig.from_env()` accepts `SQLITE_DATABASE` to choose another file or `:memory:`.
@@ -0,0 +1,83 @@
1
+ # industrial-connect
2
+
3
+ Reusable Python connectors for industrial applications. Python 3.12+, Windows and Linux.
4
+ Optional drivers, explicit resource ownership, no import-time connections.
5
+
6
+ ## Install
7
+
8
+ ```shell
9
+ pip install industrial-connect # SQLite and core
10
+ pip install "industrial-connect[postgres,env]"
11
+ pip install "industrial-connect[mqtt,opcua]"
12
+ pip install "industrial-connect[all]"
13
+ ```
14
+
15
+ Install only the drivers you need. Pin the tested library version and lock your
16
+ application's dependencies. `db` includes every database; `all` includes every extra.
17
+
18
+ ## Connectors and runnable examples
19
+
20
+ Each guide includes configuration, a realistic example, resource lifetime and error behavior.
21
+ Run examples from the checkout; `--help` lists the available options.
22
+
23
+ | Connector | Extra | Guide | Example |
24
+ | --- | --- | --- | --- |
25
+ | PostgreSQL | `postgres` | [PostgreSQL](docs/postgres.md) | `python -m examples.postgres` |
26
+ | Oracle | `oracle` | [Oracle and PL/SQL](docs/oracle.md) | `python -m examples.oracle` |
27
+ | SQL Server | `mssql` | [SQL Server](docs/mssql.md) | `python -m examples.mssql` |
28
+ | SQLite | none | [SQLite](docs/sqlite.md) | `python -m examples.sqlite` |
29
+ | QuestDB QWP | `questdb` | [WebSocket ingestion and SQL](docs/questdb.md) | `python -m examples.questdb` |
30
+ | MQTT | `mqtt` | [Queue or callback telemetry](docs/mqtt.md) | `python -m examples.mqtt` / `examples.mqtt_callback` |
31
+ | OPC UA | `opcua` | [PLC reads, writes and subscriptions](docs/opcua.md) | `python -m examples.opcua` |
32
+ | Console/files | none | [Logging](docs/logging.md) | `python -m examples.logging_setup` |
33
+ | Graylog | `graylog` | [GELF/UDP](docs/graylog.md) | `python -m examples.graylog` |
34
+
35
+ ## Quick start without a service
36
+
37
+ ```python
38
+ from industrial_connect.db import SqliteClient, SqliteConfig
39
+
40
+ with SqliteClient(SqliteConfig(database=":memory:")) as db:
41
+ db.execute("CREATE TABLE readings(equipment TEXT, temperature_c REAL)")
42
+ with db.transaction() as tx:
43
+ tx.execute("INSERT INTO readings VALUES (?, ?)", ("MILL_1", 72.5))
44
+ print(db.query("SELECT * FROM readings WHERE equipment=?", ("MILL_1",)))
45
+ ```
46
+
47
+ Every config supports explicit constructors and `from_env()`; loading a `.env` file
48
+ requires the `env` extra and an explicit `env_file` argument. See
49
+ [configuration](docs/configuration.md) and the [sample environment](examples/.env.example).
50
+ For persistent clients shared across modules, see [the sharing guide](examples/README.md).
51
+
52
+ ## Operational contracts
53
+
54
+ - Close clients after workers stop. Context managers own cleanup; closing is terminal.
55
+ - Use bound SQL parameters. Native placeholders differ by database; see the guides.
56
+ - Catch `IndustrialConnectError` or its `DependencyError`, `ConnectionError` and
57
+ `OperationError` subclasses. Native errors remain in exception chains; cleanup
58
+ failures add notes instead of hiding the original failure.
59
+ - A failed write may already have arrived. The wrapper does not retry writes; native
60
+ MQTT and QuestDB drivers have their own delivery/reconnect behavior.
61
+ - MQTT/OPC UA queues are bounded. Monitor `dropped_count`; overflow means data loss.
62
+ - Configure logging once with `setup_logging()`; modules use `get_logger(__name__)`.
63
+ - Configure TLS, certificate trust and credentials for your deployment. Avoid logging
64
+ secrets and raw driver exception chains. Graylog GELF/UDP is unencrypted.
65
+
66
+ See [database contracts](docs/databases.md) and [deployment and verification](docs/operations.md).
67
+
68
+ ## Develop and publish
69
+
70
+ ```shell
71
+ python -m pip install -e ".[all,dev]"
72
+ python manage.py check
73
+ python manage.py build
74
+ ```
75
+
76
+ The build command runs checks and creates a wheel and source archive in `dist/`.
77
+ Uploads are explicit. See [publishing](docs/publishing.md) for version bumps,
78
+ TestPyPI, PyPI and private registries, and [integration tests](tests/integration/README.md)
79
+ for disposable services. Passing unit tests alone does not validate your plant's devices,
80
+ network, database permissions or delivery requirements.
81
+
82
+ Licensed under [Apache-2.0](LICENSE). SQLite defaults to `store.db`;
83
+ `SqliteConfig.from_env()` accepts `SQLITE_DATABASE` to choose another file or `:memory:`.
@@ -0,0 +1,51 @@
1
+ # Environment variables or .env files
2
+
3
+ Every connector config supports `from_env()`. Direct constructors still work:
4
+
5
+ ```python
6
+ from industrial_connect.db import OracleClient, OracleConfig, init_database
7
+ from industrial_connect.mqtt import MqttClient, MqttConfig
8
+ from industrial_connect.opcua import OpcUaClient, OpcUaConfig
9
+
10
+ oracle = init_database("production", OracleClient(OracleConfig.from_env(env_file=".env")))
11
+ mqtt = MqttClient(MqttConfig.from_env(env_file=".env"))
12
+ opcua = OpcUaClient(OpcUaConfig.from_env(env_file=".env"))
13
+
14
+ # Process variables only: no dotenv dependency required.
15
+ config = OracleConfig.from_env()
16
+
17
+ # Custom prefix for another Oracle database; explicit arguments override env/file values.
18
+ reporting = OracleConfig.from_env(env_file=".env", prefix="REPORTING_ORACLE_", pool=True)
19
+
20
+ # Plain programmatic settings remain supported.
21
+ local = OracleConfig(dsn="localhost/service", user="app", password="example")
22
+ ```
23
+
24
+ Keys are the prefix plus the **uppercase config field name**:
25
+
26
+ | Config | Default prefix | Example key |
27
+ | --- | --- | --- |
28
+ | `OracleConfig` | `ORACLE_` | `ORACLE_DSN` |
29
+ | `PostgresConfig` | `PG` | `PGHOST`, `PGDATABASE`, `PGPOOL` |
30
+ | `SqlServerConfig` | `MSSQL_` | `MSSQL_SERVER` |
31
+ | `SqliteConfig` | `SQLITE_` | `SQLITE_DATABASE` |
32
+ | `QuestDbConfig` | `QUESTDB_` | `QUESTDB_CONF` |
33
+ | `MqttConfig` | `MQTT_` | `MQTT_HOST`, `MQTT_CLIENT_ID`, `MQTT_USERNAME` |
34
+ | `OpcUaConfig` | `OPCUA_` | `OPCUA_ENDPOINT`, `OPCUA_USERNAME`, `OPCUA_CERTIFICATE` |
35
+
36
+ QuestDB ingestion and SQL share `QuestDbConfig.from_env(env_file=".env")`;
37
+ set `QUESTDB_CONF` to a `wss::` connection string (`ws::` for explicit local plaintext).
38
+
39
+ Precedence is explicit arguments, process environment, .env values, then config defaults.
40
+ Numbers and booleans are parsed (`true/false`, `1/0`, `yes/no`, `on/off`, case-insensitive).
41
+ Empty optional values become `None`; required string values remain strings. Missing
42
+ required fields and invalid values raise errors identifying variable names without values.
43
+ The usual config validation still applies. No .env discovery or `os.environ` mutation occurs;
44
+ python-dotenv handles file quoting and interpolation. Reading an explicitly supplied file
45
+ requires the `env` extra, also included in `all`.
46
+
47
+ See [the sample file](../examples/.env.example). A service-free example is runnable with:
48
+
49
+ ```shell
50
+ python -m examples.env_config --env-file examples/.env.example
51
+ ```
@@ -0,0 +1,89 @@
1
+ # Relational databases
2
+
3
+ ```python
4
+ from industrial_connect.db import SqliteClient, SqliteConfig
5
+
6
+ with SqliteClient(SqliteConfig(database=":memory:")) as db:
7
+ db.execute("create table readings (value real)")
8
+ with db.transaction() as tx:
9
+ tx.execute("insert into readings values (?)", (1.5,))
10
+ tx.executemany("insert into readings values (?)", [(2.5,), (3.5,)])
11
+ print(db.query("select * from readings where value > ?", (2.0,)))
12
+ ```
13
+
14
+ `PostgresClient(PostgresConfig(...))`, `OracleClient(OracleConfig(...))`, and
15
+ `SqlServerClient(SqlServerConfig(...))` expose the same basic methods. All configuration
16
+ classes are frozen dataclasses with keyword-only parameters. Passwords are excluded from
17
+ their representations. Constructors validate without connecting. Database context entry
18
+ does not connect; the first operation does. `close()` is idempotent and terminal.
19
+
20
+ `query(sql, params=None)` returns dictionary rows. Column names retain driver casing;
21
+ use distinct aliases when selecting duplicate column names. `execute()` and `executemany()`
22
+ return native affected-row counts, including `-1` when the driver cannot determine one.
23
+ Keep native parameter binding: PostgreSQL/SQL Server `%s` or named `%(name)s`, Oracle
24
+ `:name`, SQLite `?` or `:name`. Never interpolate user values or identifiers into SQL.
25
+
26
+ Standalone operations commit on success and roll back on failure. `transaction()` yields
27
+ a session bound to one connection, commits on successful exit, and rolls back when an
28
+ exception escapes the block. Catch operation errors outside that block when all-or-nothing
29
+ behavior is required. A session is invalid after exit. Database DDL follows native behavior:
30
+ Oracle DDL implicitly commits and cannot be made transactional by this wrapper.
31
+
32
+ Failures raise `ConnectionError` or `OperationError`, with the driver exception in
33
+ `__cause__`. Empty query results mean a successful query with zero rows. A failed commit
34
+ can have an uncertain outcome; do not retry writes blindly. No SQL operations are retried.
35
+ Wrapper error text excludes SQL, bind values and credentials; driver exception chains and
36
+ application log messages can still contain sensitive data.
37
+
38
+ ### Connection ownership
39
+
40
+ - PostgreSQL opens per-operation connections by default. Set `pool=True` for a native
41
+ Psycopg pool, created on first use. Pool bounds and acquisition timeout are configurable;
42
+ exhaustion raises an error. Returned connections commit or roll back before reuse.
43
+ - Oracle opens per-operation connections by default; `pool=True` uses its native pool with
44
+ a timed acquisition. Thin mode is the default. Call `init_oracle_thick(lib_dir=...)`
45
+ explicitly before any Oracle connections to use installed Oracle Client libraries.
46
+ Thick/Thin selection is process-wide; old servers may require Thick mode.
47
+ - SQL Server opens per-operation connections; no custom pooling. Its encryption setting
48
+ defaults to `require`. Certificate verification and trust settings are controlled by
49
+ FreeTDS configuration; encryption alone is not a certificate trust policy. Native
50
+ pymssql/FreeTDS timeout settings can affect the process; prefer consistent timeouts.
51
+ - SQLite retains one lazy connection, including for `:memory:`, and serializes operations
52
+ across calling threads. Nested transactions are rejected; use the active session.
53
+
54
+ Share a client instance, not a session or cursor, between application modules. The optional
55
+ named registry provides `init_database(name, client)`, `get_database(name)`,
56
+ `close_database(name)`, and `close_all_databases()`, all importable from `industrial_connect.db`.
57
+ For example, `oracle = init_database("production", OracleClient(config))` returns that
58
+ same client; any file can call `get_database("production").query(...)` without passing
59
+ objects through handlers. See the [named database examples](../examples/README.md).
60
+ Close registered clients through the registry after workers finish. Ordinary unregistered
61
+ clients can still be used independently. Do not share clients across processes or close pooled clients while
62
+ operations are in flight. PostgreSQL defaults to `sslmode="verify-full"`; configure
63
+ `sslrootcert` for your CA. Plaintext connections require explicit configuration.
64
+ Oracle accepts native TCPS/wallet options in its DSN; configure them for your deployment.
65
+
66
+ ### Oracle PL/SQL
67
+
68
+ ```python
69
+ # client is an OracleClient configured by the application
70
+ import oracledb
71
+
72
+ with client.transaction() as tx:
73
+ result = tx.call(
74
+ "begin :total := :input + 1; open :rows for select :input as value from dual; end;",
75
+ {"input": 41},
76
+ {"total": oracledb.DB_TYPE_NUMBER, "rows": oracledb.DB_TYPE_CURSOR},
77
+ )
78
+ print(result.out_binds, result.cursors, result.implicit_results)
79
+ ```
80
+
81
+ Output types accept native constants (`oracledb.DB_TYPE_NUMBER`, `oracledb.DB_TYPE_VARCHAR`,
82
+ `oracledb.DB_TYPE_CURSOR`, etc.), Python types (`int`, `str`, etc.), and legacy string names.
83
+ Type hints cover native Oracle types and Oracle transaction sessions. Shared database
84
+ methods expose `QueryParams`, `Row`, affected-row counts, and typed context-manager results.
85
+ Optional drivers are imported for type checking only until a connection is used.
86
+ Output REF CURSORs and
87
+ implicit results are fully fetched before cursor cleanup. Client-level `call()` commits
88
+ on success; session-level `call()` participates in its surrounding transaction. There is
89
+ no detached `commit()` method that might accidentally use another connection.
@@ -0,0 +1,25 @@
1
+ # Graylog
2
+
3
+ Install `industrial-connect[graylog]`. Configure an approved Graylog GELF/UDP input:
4
+
5
+ ```shell
6
+ python -m examples.graylog --host graylog.internal --port 12201
7
+ ```
8
+
9
+ Alternatively set `GRAYLOG_HOST` and `GRAYLOG_PORT`. [The example](../examples/graylog.py)
10
+ adds structured `equipment_id` and `temperature_c` fields, retains console output,
11
+ and closes the handlers it owns at shutdown. This only sends an event; it cannot
12
+ confirm that Graylog received or indexed it.
13
+
14
+ `setup_logging("collector", graylog_host=..., graylog_port=...)` uses graypy's
15
+ GELF/UDP handler. UDP provides neither delivery acknowledgements nor TLS. Use an
16
+ appropriate protected network, and use your existing log shipping infrastructure
17
+ when authenticated encrypted or durable delivery is required. No credentials, raw
18
+ connection configurations or driver exception chains belong in log messages.
19
+
20
+ Configure the outputs once at startup and use `get_logger(__name__)` in every
21
+ module. Read [logging configuration and ownership](logging.md). The helper attaches
22
+ its handlers to the root logger, preserving handlers installed by other code. Console
23
+ and file output stay readable text; the Graylog handler produces GELF JSON with
24
+ `app_name` as the facility and structured `extra` fields. Call `shutdown_logging()`
25
+ after application workers stop to close only the helper's outputs.