fdc-shared-kernel 0.0.3__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.
- fdc_shared_kernel-0.0.3/PKG-INFO +159 -0
- fdc_shared_kernel-0.0.3/README.md +130 -0
- fdc_shared_kernel-0.0.3/pyproject.toml +25 -0
- fdc_shared_kernel-0.0.3/requirements.txt +18 -0
- fdc_shared_kernel-0.0.3/setup.cfg +4 -0
- fdc_shared_kernel-0.0.3/src/fdc_shared_kernel.egg-info/PKG-INFO +159 -0
- fdc_shared_kernel-0.0.3/src/fdc_shared_kernel.egg-info/SOURCES.txt +37 -0
- fdc_shared_kernel-0.0.3/src/fdc_shared_kernel.egg-info/dependency_links.txt +1 -0
- fdc_shared_kernel-0.0.3/src/fdc_shared_kernel.egg-info/requires.txt +18 -0
- fdc_shared_kernel-0.0.3/src/fdc_shared_kernel.egg-info/top_level.txt +1 -0
- fdc_shared_kernel-0.0.3/src/shared_kernel/__init__.py +0 -0
- fdc_shared_kernel-0.0.3/src/shared_kernel/config/__init__.py +49 -0
- fdc_shared_kernel-0.0.3/src/shared_kernel/database/__init__.py +43 -0
- fdc_shared_kernel-0.0.3/src/shared_kernel/exceptions/__init__.py +7 -0
- fdc_shared_kernel-0.0.3/src/shared_kernel/exceptions/configuration_exceptions.py +20 -0
- fdc_shared_kernel-0.0.3/src/shared_kernel/exceptions/custom_exceptions.py +14 -0
- fdc_shared_kernel-0.0.3/src/shared_kernel/exceptions/data_validation_exceptions.py +26 -0
- fdc_shared_kernel-0.0.3/src/shared_kernel/exceptions/http_exceptions.py +60 -0
- fdc_shared_kernel-0.0.3/src/shared_kernel/exceptions/infrastructure_exceptions.py +26 -0
- fdc_shared_kernel-0.0.3/src/shared_kernel/exceptions/operational_exceptions.py +26 -0
- fdc_shared_kernel-0.0.3/src/shared_kernel/exceptions/security_exceptions.py +26 -0
- fdc_shared_kernel-0.0.3/src/shared_kernel/interfaces/__init__.py +0 -0
- fdc_shared_kernel-0.0.3/src/shared_kernel/interfaces/databus.py +73 -0
- fdc_shared_kernel-0.0.3/src/shared_kernel/logger/__init__.py +75 -0
- fdc_shared_kernel-0.0.3/src/shared_kernel/messaging/__init__.py +1 -0
- fdc_shared_kernel-0.0.3/src/shared_kernel/messaging/nats_databus.py +171 -0
- fdc_shared_kernel-0.0.3/src/shared_kernel/models/__init__.py +0 -0
- fdc_shared_kernel-0.0.3/src/shared_kernel/tests/__init__.py +0 -0
- fdc_shared_kernel-0.0.3/src/shared_kernel/tests/config/test_config.py +35 -0
- fdc_shared_kernel-0.0.3/src/shared_kernel/tests/logger/test_logger.py +48 -0
- fdc_shared_kernel-0.0.3/src/shared_kernel/tests/messaging/test_nats_interface.py +36 -0
- fdc_shared_kernel-0.0.3/src/shared_kernel/tests/utils/test_data_validators.py +18 -0
- fdc_shared_kernel-0.0.3/src/shared_kernel/tests/utils/test_date_format_utils.py +20 -0
- fdc_shared_kernel-0.0.3/src/shared_kernel/tests/utils/test_string_utils.py +28 -0
- fdc_shared_kernel-0.0.3/src/shared_kernel/tests/utils/utils.py +618 -0
- fdc_shared_kernel-0.0.3/src/shared_kernel/utils/__init__.py +3 -0
- fdc_shared_kernel-0.0.3/src/shared_kernel/utils/data_validators_utils.py +15 -0
- fdc_shared_kernel-0.0.3/src/shared_kernel/utils/date_format_utils.py +13 -0
- fdc_shared_kernel-0.0.3/src/shared_kernel/utils/string_utils.py +28 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: fdc_shared_kernel
|
|
3
|
+
Version: 0.0.3
|
|
4
|
+
Summary: Shared library for microservice
|
|
5
|
+
Author-email: Shikhil S <shikhil.s@dbizsolution.com>
|
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Requires-Python: >=3.7
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
Requires-Dist: alembic==1.13.2
|
|
12
|
+
Requires-Dist: asynctest==0.13.0
|
|
13
|
+
Requires-Dist: build==1.2.1
|
|
14
|
+
Requires-Dist: colorama==0.4.6
|
|
15
|
+
Requires-Dist: greenlet==3.0.3
|
|
16
|
+
Requires-Dist: iniconfig==2.0.0
|
|
17
|
+
Requires-Dist: Mako==1.3.5
|
|
18
|
+
Requires-Dist: MarkupSafe==2.1.5
|
|
19
|
+
Requires-Dist: nats-py==2.8.0
|
|
20
|
+
Requires-Dist: packaging==24.1
|
|
21
|
+
Requires-Dist: pluggy==1.5.0
|
|
22
|
+
Requires-Dist: psycopg2-binary==2.9.9
|
|
23
|
+
Requires-Dist: pytest==8.2.2
|
|
24
|
+
Requires-Dist: pytest-asyncio==0.23.8
|
|
25
|
+
Requires-Dist: python-dotenv==1.0.1
|
|
26
|
+
Requires-Dist: setuptools==71.0.0
|
|
27
|
+
Requires-Dist: SQLAlchemy==2.0.31
|
|
28
|
+
Requires-Dist: typing_extensions==4.12.2
|
|
29
|
+
|
|
30
|
+
# Shared Kernel
|
|
31
|
+
|
|
32
|
+
Shared Kernel is a lightweight, modular Python library designed to facilitate rapid development of microservices. It provides essential utilities for data manipulation, logging, configuration management, and database connectivity, making it an ideal foundation for building scalable and maintainable microservices.
|
|
33
|
+
|
|
34
|
+
## Table of Contents
|
|
35
|
+
|
|
36
|
+
- [Getting Started](#getting-started)
|
|
37
|
+
- [Prerequisites](#prerequisites)
|
|
38
|
+
- [Installation](#installation)
|
|
39
|
+
- [Usage](#usage)
|
|
40
|
+
- [Importing Modules](#importing-modules)
|
|
41
|
+
- [Initializing Database Connection](#initializing-database-connection)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
## Getting Started
|
|
45
|
+
|
|
46
|
+
### Prerequisites
|
|
47
|
+
|
|
48
|
+
- Python 3.6+
|
|
49
|
+
- Pip
|
|
50
|
+
|
|
51
|
+
### Installation
|
|
52
|
+
|
|
53
|
+
To install Shared Kernel, clone the repository and install it using pip:
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
git clone https://bitbucket.org/Weavers/shared-kernel.git
|
|
57
|
+
cd shared-kernel pip install .
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
##### Step 1: Set Up Your Environment
|
|
61
|
+
First, ensure you have Python installed on your system. Then, set up a virtual environment for your project to manage dependencies cleanly. Open your terminal and navigate to your project directory:
|
|
62
|
+
|
|
63
|
+
```sh
|
|
64
|
+
cd path/to/shared-kernel
|
|
65
|
+
python -m venv venv
|
|
66
|
+
source venv/bin/activate # On Windows, use `venv\Scripts\activate`
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
##### Step 2: Install Python build frontend.
|
|
70
|
+
Ensure you python's build frontend. installed in your environment. This is necessary for building the wheel package from **.toml** file. You can install them using pip:
|
|
71
|
+
```sh
|
|
72
|
+
pip install --upgrade build
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
##### Step 3: Build the Wheel Package
|
|
76
|
+
```sh
|
|
77
|
+
python -m build
|
|
78
|
+
```
|
|
79
|
+
This command will build a wheel distribution and also a source distribution. After running this command, you'll find the .whl and a tar file inside the dist/ directory within your project folder.
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
##### Step 4: Distribute the Wheel
|
|
83
|
+
Now that you have a .whl file, you can distribute it to others. Users can install your library using pip by pointing to the .whl file:
|
|
84
|
+
|
|
85
|
+
```sh
|
|
86
|
+
pip install dist/shared_kernel-0.1.0-py3-none-any.whl
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
## Usage
|
|
91
|
+
|
|
92
|
+
### Importing Modules
|
|
93
|
+
|
|
94
|
+
Import the required modules from Shared Kernel into your project:
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
from shared_kernel.logger import Logger
|
|
98
|
+
from shared_kernel.config import Config
|
|
99
|
+
from dotenv import find_dotenv
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def main():
|
|
103
|
+
logger = Logger(name="my_app")
|
|
104
|
+
logger.configure_logger()
|
|
105
|
+
|
|
106
|
+
# Specify the path to the .env file if it's not in the current directory
|
|
107
|
+
config_manager = Config(env_path=find_dotenv())
|
|
108
|
+
|
|
109
|
+
# Access environment variables
|
|
110
|
+
api_key = config_manager.get("KEY", "default_api_key")
|
|
111
|
+
|
|
112
|
+
# Example usage
|
|
113
|
+
logger.logger.info("This is an info message.")
|
|
114
|
+
logger.logger.error("This is an error message.")
|
|
115
|
+
logger.logger.info(api_key)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
if __name__ == "__main__":
|
|
119
|
+
main()
|
|
120
|
+
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
### Initializing Database Connection
|
|
125
|
+
|
|
126
|
+
Use the `DB` class to initialize a database connection:
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
from shared_kernel.DB import DB
|
|
130
|
+
|
|
131
|
+
db_instance = DB("postgresql://user:password@localhost/dbname")
|
|
132
|
+
engine, SessionLocal = db_instance.init_db_connection()
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
### Initializing NATS Connection
|
|
140
|
+
|
|
141
|
+
Use the `NATSClient` class to initialize a messaging connection:
|
|
142
|
+
|
|
143
|
+
```
|
|
144
|
+
from shared_kernel.messaging import NATSClient
|
|
145
|
+
import asyncio
|
|
146
|
+
|
|
147
|
+
def run():
|
|
148
|
+
nats_instance = NATSClient("nats://localhost:4222")
|
|
149
|
+
await nc_interface.connect()
|
|
150
|
+
|
|
151
|
+
async def message_callback(data):
|
|
152
|
+
print(f"Received a message: {data}")
|
|
153
|
+
|
|
154
|
+
await nc_interface.subscribe("example_subject", message_callback)
|
|
155
|
+
await nc_interface.publish("example_subject", "Hello NATS!")
|
|
156
|
+
|
|
157
|
+
if __name__ == '__main__':
|
|
158
|
+
asyncio.run(run())
|
|
159
|
+
```
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# Shared Kernel
|
|
2
|
+
|
|
3
|
+
Shared Kernel is a lightweight, modular Python library designed to facilitate rapid development of microservices. It provides essential utilities for data manipulation, logging, configuration management, and database connectivity, making it an ideal foundation for building scalable and maintainable microservices.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Getting Started](#getting-started)
|
|
8
|
+
- [Prerequisites](#prerequisites)
|
|
9
|
+
- [Installation](#installation)
|
|
10
|
+
- [Usage](#usage)
|
|
11
|
+
- [Importing Modules](#importing-modules)
|
|
12
|
+
- [Initializing Database Connection](#initializing-database-connection)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## Getting Started
|
|
16
|
+
|
|
17
|
+
### Prerequisites
|
|
18
|
+
|
|
19
|
+
- Python 3.6+
|
|
20
|
+
- Pip
|
|
21
|
+
|
|
22
|
+
### Installation
|
|
23
|
+
|
|
24
|
+
To install Shared Kernel, clone the repository and install it using pip:
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
git clone https://bitbucket.org/Weavers/shared-kernel.git
|
|
28
|
+
cd shared-kernel pip install .
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
##### Step 1: Set Up Your Environment
|
|
32
|
+
First, ensure you have Python installed on your system. Then, set up a virtual environment for your project to manage dependencies cleanly. Open your terminal and navigate to your project directory:
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
cd path/to/shared-kernel
|
|
36
|
+
python -m venv venv
|
|
37
|
+
source venv/bin/activate # On Windows, use `venv\Scripts\activate`
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
##### Step 2: Install Python build frontend.
|
|
41
|
+
Ensure you python's build frontend. installed in your environment. This is necessary for building the wheel package from **.toml** file. You can install them using pip:
|
|
42
|
+
```sh
|
|
43
|
+
pip install --upgrade build
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
##### Step 3: Build the Wheel Package
|
|
47
|
+
```sh
|
|
48
|
+
python -m build
|
|
49
|
+
```
|
|
50
|
+
This command will build a wheel distribution and also a source distribution. After running this command, you'll find the .whl and a tar file inside the dist/ directory within your project folder.
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
##### Step 4: Distribute the Wheel
|
|
54
|
+
Now that you have a .whl file, you can distribute it to others. Users can install your library using pip by pointing to the .whl file:
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
pip install dist/shared_kernel-0.1.0-py3-none-any.whl
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
## Usage
|
|
62
|
+
|
|
63
|
+
### Importing Modules
|
|
64
|
+
|
|
65
|
+
Import the required modules from Shared Kernel into your project:
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
from shared_kernel.logger import Logger
|
|
69
|
+
from shared_kernel.config import Config
|
|
70
|
+
from dotenv import find_dotenv
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def main():
|
|
74
|
+
logger = Logger(name="my_app")
|
|
75
|
+
logger.configure_logger()
|
|
76
|
+
|
|
77
|
+
# Specify the path to the .env file if it's not in the current directory
|
|
78
|
+
config_manager = Config(env_path=find_dotenv())
|
|
79
|
+
|
|
80
|
+
# Access environment variables
|
|
81
|
+
api_key = config_manager.get("KEY", "default_api_key")
|
|
82
|
+
|
|
83
|
+
# Example usage
|
|
84
|
+
logger.logger.info("This is an info message.")
|
|
85
|
+
logger.logger.error("This is an error message.")
|
|
86
|
+
logger.logger.info(api_key)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
if __name__ == "__main__":
|
|
90
|
+
main()
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
### Initializing Database Connection
|
|
96
|
+
|
|
97
|
+
Use the `DB` class to initialize a database connection:
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
from shared_kernel.DB import DB
|
|
101
|
+
|
|
102
|
+
db_instance = DB("postgresql://user:password@localhost/dbname")
|
|
103
|
+
engine, SessionLocal = db_instance.init_db_connection()
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
### Initializing NATS Connection
|
|
111
|
+
|
|
112
|
+
Use the `NATSClient` class to initialize a messaging connection:
|
|
113
|
+
|
|
114
|
+
```
|
|
115
|
+
from shared_kernel.messaging import NATSClient
|
|
116
|
+
import asyncio
|
|
117
|
+
|
|
118
|
+
def run():
|
|
119
|
+
nats_instance = NATSClient("nats://localhost:4222")
|
|
120
|
+
await nc_interface.connect()
|
|
121
|
+
|
|
122
|
+
async def message_callback(data):
|
|
123
|
+
print(f"Received a message: {data}")
|
|
124
|
+
|
|
125
|
+
await nc_interface.subscribe("example_subject", message_callback)
|
|
126
|
+
await nc_interface.publish("example_subject", "Hello NATS!")
|
|
127
|
+
|
|
128
|
+
if __name__ == '__main__':
|
|
129
|
+
asyncio.run(run())
|
|
130
|
+
```
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "fdc_shared_kernel"
|
|
7
|
+
version = "0.0.3"
|
|
8
|
+
requires-python = ">=3.7"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
description = "Shared library for microservice"
|
|
11
|
+
authors = [
|
|
12
|
+
{name="Shikhil S", email="shikhil.s@dbizsolution.com"},
|
|
13
|
+
]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
]
|
|
19
|
+
dynamic = ["dependencies"]
|
|
20
|
+
|
|
21
|
+
[tool.setuptools.dynamic]
|
|
22
|
+
dependencies = {file = ["requirements.txt"]}
|
|
23
|
+
|
|
24
|
+
[tool.setuptools]
|
|
25
|
+
packages = { find = { where = ["src"] } }
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
alembic==1.13.2
|
|
2
|
+
asynctest==0.13.0
|
|
3
|
+
build==1.2.1
|
|
4
|
+
colorama==0.4.6
|
|
5
|
+
greenlet==3.0.3
|
|
6
|
+
iniconfig==2.0.0
|
|
7
|
+
Mako==1.3.5
|
|
8
|
+
MarkupSafe==2.1.5
|
|
9
|
+
nats-py==2.8.0
|
|
10
|
+
packaging==24.1
|
|
11
|
+
pluggy==1.5.0
|
|
12
|
+
psycopg2-binary==2.9.9
|
|
13
|
+
pytest==8.2.2
|
|
14
|
+
pytest-asyncio==0.23.8
|
|
15
|
+
python-dotenv==1.0.1
|
|
16
|
+
setuptools==71.0.0
|
|
17
|
+
SQLAlchemy==2.0.31
|
|
18
|
+
typing_extensions==4.12.2
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: fdc_shared_kernel
|
|
3
|
+
Version: 0.0.3
|
|
4
|
+
Summary: Shared library for microservice
|
|
5
|
+
Author-email: Shikhil S <shikhil.s@dbizsolution.com>
|
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Requires-Python: >=3.7
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
Requires-Dist: alembic==1.13.2
|
|
12
|
+
Requires-Dist: asynctest==0.13.0
|
|
13
|
+
Requires-Dist: build==1.2.1
|
|
14
|
+
Requires-Dist: colorama==0.4.6
|
|
15
|
+
Requires-Dist: greenlet==3.0.3
|
|
16
|
+
Requires-Dist: iniconfig==2.0.0
|
|
17
|
+
Requires-Dist: Mako==1.3.5
|
|
18
|
+
Requires-Dist: MarkupSafe==2.1.5
|
|
19
|
+
Requires-Dist: nats-py==2.8.0
|
|
20
|
+
Requires-Dist: packaging==24.1
|
|
21
|
+
Requires-Dist: pluggy==1.5.0
|
|
22
|
+
Requires-Dist: psycopg2-binary==2.9.9
|
|
23
|
+
Requires-Dist: pytest==8.2.2
|
|
24
|
+
Requires-Dist: pytest-asyncio==0.23.8
|
|
25
|
+
Requires-Dist: python-dotenv==1.0.1
|
|
26
|
+
Requires-Dist: setuptools==71.0.0
|
|
27
|
+
Requires-Dist: SQLAlchemy==2.0.31
|
|
28
|
+
Requires-Dist: typing_extensions==4.12.2
|
|
29
|
+
|
|
30
|
+
# Shared Kernel
|
|
31
|
+
|
|
32
|
+
Shared Kernel is a lightweight, modular Python library designed to facilitate rapid development of microservices. It provides essential utilities for data manipulation, logging, configuration management, and database connectivity, making it an ideal foundation for building scalable and maintainable microservices.
|
|
33
|
+
|
|
34
|
+
## Table of Contents
|
|
35
|
+
|
|
36
|
+
- [Getting Started](#getting-started)
|
|
37
|
+
- [Prerequisites](#prerequisites)
|
|
38
|
+
- [Installation](#installation)
|
|
39
|
+
- [Usage](#usage)
|
|
40
|
+
- [Importing Modules](#importing-modules)
|
|
41
|
+
- [Initializing Database Connection](#initializing-database-connection)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
## Getting Started
|
|
45
|
+
|
|
46
|
+
### Prerequisites
|
|
47
|
+
|
|
48
|
+
- Python 3.6+
|
|
49
|
+
- Pip
|
|
50
|
+
|
|
51
|
+
### Installation
|
|
52
|
+
|
|
53
|
+
To install Shared Kernel, clone the repository and install it using pip:
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
git clone https://bitbucket.org/Weavers/shared-kernel.git
|
|
57
|
+
cd shared-kernel pip install .
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
##### Step 1: Set Up Your Environment
|
|
61
|
+
First, ensure you have Python installed on your system. Then, set up a virtual environment for your project to manage dependencies cleanly. Open your terminal and navigate to your project directory:
|
|
62
|
+
|
|
63
|
+
```sh
|
|
64
|
+
cd path/to/shared-kernel
|
|
65
|
+
python -m venv venv
|
|
66
|
+
source venv/bin/activate # On Windows, use `venv\Scripts\activate`
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
##### Step 2: Install Python build frontend.
|
|
70
|
+
Ensure you python's build frontend. installed in your environment. This is necessary for building the wheel package from **.toml** file. You can install them using pip:
|
|
71
|
+
```sh
|
|
72
|
+
pip install --upgrade build
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
##### Step 3: Build the Wheel Package
|
|
76
|
+
```sh
|
|
77
|
+
python -m build
|
|
78
|
+
```
|
|
79
|
+
This command will build a wheel distribution and also a source distribution. After running this command, you'll find the .whl and a tar file inside the dist/ directory within your project folder.
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
##### Step 4: Distribute the Wheel
|
|
83
|
+
Now that you have a .whl file, you can distribute it to others. Users can install your library using pip by pointing to the .whl file:
|
|
84
|
+
|
|
85
|
+
```sh
|
|
86
|
+
pip install dist/shared_kernel-0.1.0-py3-none-any.whl
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
## Usage
|
|
91
|
+
|
|
92
|
+
### Importing Modules
|
|
93
|
+
|
|
94
|
+
Import the required modules from Shared Kernel into your project:
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
from shared_kernel.logger import Logger
|
|
98
|
+
from shared_kernel.config import Config
|
|
99
|
+
from dotenv import find_dotenv
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def main():
|
|
103
|
+
logger = Logger(name="my_app")
|
|
104
|
+
logger.configure_logger()
|
|
105
|
+
|
|
106
|
+
# Specify the path to the .env file if it's not in the current directory
|
|
107
|
+
config_manager = Config(env_path=find_dotenv())
|
|
108
|
+
|
|
109
|
+
# Access environment variables
|
|
110
|
+
api_key = config_manager.get("KEY", "default_api_key")
|
|
111
|
+
|
|
112
|
+
# Example usage
|
|
113
|
+
logger.logger.info("This is an info message.")
|
|
114
|
+
logger.logger.error("This is an error message.")
|
|
115
|
+
logger.logger.info(api_key)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
if __name__ == "__main__":
|
|
119
|
+
main()
|
|
120
|
+
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
### Initializing Database Connection
|
|
125
|
+
|
|
126
|
+
Use the `DB` class to initialize a database connection:
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
from shared_kernel.DB import DB
|
|
130
|
+
|
|
131
|
+
db_instance = DB("postgresql://user:password@localhost/dbname")
|
|
132
|
+
engine, SessionLocal = db_instance.init_db_connection()
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
### Initializing NATS Connection
|
|
140
|
+
|
|
141
|
+
Use the `NATSClient` class to initialize a messaging connection:
|
|
142
|
+
|
|
143
|
+
```
|
|
144
|
+
from shared_kernel.messaging import NATSClient
|
|
145
|
+
import asyncio
|
|
146
|
+
|
|
147
|
+
def run():
|
|
148
|
+
nats_instance = NATSClient("nats://localhost:4222")
|
|
149
|
+
await nc_interface.connect()
|
|
150
|
+
|
|
151
|
+
async def message_callback(data):
|
|
152
|
+
print(f"Received a message: {data}")
|
|
153
|
+
|
|
154
|
+
await nc_interface.subscribe("example_subject", message_callback)
|
|
155
|
+
await nc_interface.publish("example_subject", "Hello NATS!")
|
|
156
|
+
|
|
157
|
+
if __name__ == '__main__':
|
|
158
|
+
asyncio.run(run())
|
|
159
|
+
```
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
requirements.txt
|
|
4
|
+
src/fdc_shared_kernel.egg-info/PKG-INFO
|
|
5
|
+
src/fdc_shared_kernel.egg-info/SOURCES.txt
|
|
6
|
+
src/fdc_shared_kernel.egg-info/dependency_links.txt
|
|
7
|
+
src/fdc_shared_kernel.egg-info/requires.txt
|
|
8
|
+
src/fdc_shared_kernel.egg-info/top_level.txt
|
|
9
|
+
src/shared_kernel/__init__.py
|
|
10
|
+
src/shared_kernel/config/__init__.py
|
|
11
|
+
src/shared_kernel/database/__init__.py
|
|
12
|
+
src/shared_kernel/exceptions/__init__.py
|
|
13
|
+
src/shared_kernel/exceptions/configuration_exceptions.py
|
|
14
|
+
src/shared_kernel/exceptions/custom_exceptions.py
|
|
15
|
+
src/shared_kernel/exceptions/data_validation_exceptions.py
|
|
16
|
+
src/shared_kernel/exceptions/http_exceptions.py
|
|
17
|
+
src/shared_kernel/exceptions/infrastructure_exceptions.py
|
|
18
|
+
src/shared_kernel/exceptions/operational_exceptions.py
|
|
19
|
+
src/shared_kernel/exceptions/security_exceptions.py
|
|
20
|
+
src/shared_kernel/interfaces/__init__.py
|
|
21
|
+
src/shared_kernel/interfaces/databus.py
|
|
22
|
+
src/shared_kernel/logger/__init__.py
|
|
23
|
+
src/shared_kernel/messaging/__init__.py
|
|
24
|
+
src/shared_kernel/messaging/nats_databus.py
|
|
25
|
+
src/shared_kernel/models/__init__.py
|
|
26
|
+
src/shared_kernel/tests/__init__.py
|
|
27
|
+
src/shared_kernel/tests/config/test_config.py
|
|
28
|
+
src/shared_kernel/tests/logger/test_logger.py
|
|
29
|
+
src/shared_kernel/tests/messaging/test_nats_interface.py
|
|
30
|
+
src/shared_kernel/tests/utils/test_data_validators.py
|
|
31
|
+
src/shared_kernel/tests/utils/test_date_format_utils.py
|
|
32
|
+
src/shared_kernel/tests/utils/test_string_utils.py
|
|
33
|
+
src/shared_kernel/tests/utils/utils.py
|
|
34
|
+
src/shared_kernel/utils/__init__.py
|
|
35
|
+
src/shared_kernel/utils/data_validators_utils.py
|
|
36
|
+
src/shared_kernel/utils/date_format_utils.py
|
|
37
|
+
src/shared_kernel/utils/string_utils.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
alembic==1.13.2
|
|
2
|
+
asynctest==0.13.0
|
|
3
|
+
build==1.2.1
|
|
4
|
+
colorama==0.4.6
|
|
5
|
+
greenlet==3.0.3
|
|
6
|
+
iniconfig==2.0.0
|
|
7
|
+
Mako==1.3.5
|
|
8
|
+
MarkupSafe==2.1.5
|
|
9
|
+
nats-py==2.8.0
|
|
10
|
+
packaging==24.1
|
|
11
|
+
pluggy==1.5.0
|
|
12
|
+
psycopg2-binary==2.9.9
|
|
13
|
+
pytest==8.2.2
|
|
14
|
+
pytest-asyncio==0.23.8
|
|
15
|
+
python-dotenv==1.0.1
|
|
16
|
+
setuptools==71.0.0
|
|
17
|
+
SQLAlchemy==2.0.31
|
|
18
|
+
typing_extensions==4.12.2
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
shared_kernel
|
|
File without changes
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from typing import Any
|
|
3
|
+
from dotenv import load_dotenv, find_dotenv
|
|
4
|
+
from shared_kernel.exceptions import MissingConfiguration, InvalidConfiguration
|
|
5
|
+
import logging
|
|
6
|
+
|
|
7
|
+
logging.basicConfig(level=logging.INFO)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Config:
|
|
11
|
+
|
|
12
|
+
_instance = None
|
|
13
|
+
|
|
14
|
+
def __new__(cls, env_path=None):
|
|
15
|
+
if cls._instance is None:
|
|
16
|
+
cls._instance = super(Config, cls).__new__(cls)
|
|
17
|
+
cls._instance._initialize(env_path)
|
|
18
|
+
return cls._instance
|
|
19
|
+
|
|
20
|
+
def _initialize(self, env_path=None):
|
|
21
|
+
"""
|
|
22
|
+
Initializes the Config class with an optional path to the .env file.
|
|
23
|
+
|
|
24
|
+
:param env_path: Optional path to the .env file. Defaults to finding the .env file in the current directory.
|
|
25
|
+
"""
|
|
26
|
+
if env_path is None:
|
|
27
|
+
dotenv_path = find_dotenv()
|
|
28
|
+
if not dotenv_path:
|
|
29
|
+
logging.error(".env file not found")
|
|
30
|
+
raise InvalidConfiguration(".env file not found")
|
|
31
|
+
else:
|
|
32
|
+
dotenv_path = env_path
|
|
33
|
+
|
|
34
|
+
logging.info(f"Loading environment variables from {dotenv_path}")
|
|
35
|
+
load_dotenv(dotenv_path)
|
|
36
|
+
|
|
37
|
+
@staticmethod
|
|
38
|
+
def get(key: str, default: Any = None) -> Any:
|
|
39
|
+
"""
|
|
40
|
+
Retrieves the value of an environment variable.
|
|
41
|
+
|
|
42
|
+
:param key: The name of the environment variable.
|
|
43
|
+
:param default: Default value to return if the environment variable is not set.
|
|
44
|
+
:return: The value of the environment variable.
|
|
45
|
+
"""
|
|
46
|
+
value = os.getenv(key, default)
|
|
47
|
+
if value is None:
|
|
48
|
+
raise MissingConfiguration(key)
|
|
49
|
+
return value
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from sqlalchemy import create_engine
|
|
2
|
+
from sqlalchemy.ext.declarative import declarative_base
|
|
3
|
+
from sqlalchemy.orm import sessionmaker
|
|
4
|
+
from shared_kernel.logger import Logger
|
|
5
|
+
from typing import Tuple
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class DB:
|
|
9
|
+
def __init__(self, db_url: str):
|
|
10
|
+
"""
|
|
11
|
+
Initializes the DB class with the provided database configuration.
|
|
12
|
+
|
|
13
|
+
:param db_url: The database URL (e.g., postgresql://user:password@localhost/dbname).
|
|
14
|
+
"""
|
|
15
|
+
self.engine = create_engine(db_url, pool_size=20, max_overflow=100)
|
|
16
|
+
self.SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=self.engine)
|
|
17
|
+
self.Base = declarative_base()
|
|
18
|
+
self.logger = Logger(name="database")
|
|
19
|
+
self.logger.configure_logger()
|
|
20
|
+
|
|
21
|
+
def init_db_connection(self) -> Tuple[create_engine, sessionmaker]:
|
|
22
|
+
"""
|
|
23
|
+
Initializes the database connection and returns the engine and session maker.
|
|
24
|
+
|
|
25
|
+
:return: A tuple containing the SQLAlchemy engine and session maker.
|
|
26
|
+
"""
|
|
27
|
+
self.logger.info("Database connection initialized successfully.")
|
|
28
|
+
return self.engine, self.SessionLocal
|
|
29
|
+
|
|
30
|
+
def create_tables(self):
|
|
31
|
+
"""
|
|
32
|
+
Creates all tables stored in declarative Base.
|
|
33
|
+
"""
|
|
34
|
+
self.logger.info("Creating tables...")
|
|
35
|
+
self.Base.metadata.create_all(bind=self.engine)
|
|
36
|
+
self.logger.info("Tables created successfully.")
|
|
37
|
+
|
|
38
|
+
def close_session(self):
|
|
39
|
+
"""
|
|
40
|
+
Closes the database session.
|
|
41
|
+
"""
|
|
42
|
+
self.SessionLocal.remove()
|
|
43
|
+
self.logger.info("Session closed successfully.")
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
from shared_kernel.exceptions.configuration_exceptions import *
|
|
2
|
+
from shared_kernel.exceptions.custom_exceptions import *
|
|
3
|
+
from shared_kernel.exceptions.data_validation_exceptions import *
|
|
4
|
+
from shared_kernel.exceptions.http_exceptions import *
|
|
5
|
+
from shared_kernel.exceptions.infrastructure_exceptions import *
|
|
6
|
+
from shared_kernel.exceptions.operational_exceptions import *
|
|
7
|
+
from shared_kernel.exceptions.security_exceptions import *
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
class ConfigurationException(Exception):
|
|
2
|
+
"""Base class for all configuration exceptions."""
|
|
3
|
+
def __init__(self, message: str = "", config_key: str = "") -> None:
|
|
4
|
+
super().__init__(message)
|
|
5
|
+
self.config_key = config_key
|
|
6
|
+
|
|
7
|
+
def __str__(self) -> str:
|
|
8
|
+
return f"{type(self).__name__}: {self.args[0]} (Config Key: {self.config_key})"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class MissingConfiguration(ConfigurationException):
|
|
12
|
+
"""Raised when a required configuration setting is missing."""
|
|
13
|
+
def __init__(self, message: str = "Required configuration setting is missing", config_key: str = "") -> None:
|
|
14
|
+
super().__init__(message=message, config_key=config_key)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class InvalidConfiguration(ConfigurationException):
|
|
18
|
+
"""Raised when a configuration setting is invalid."""
|
|
19
|
+
def __init__(self, message: str = "Invalid configuration setting", config_key: str = "", valid_value: str = "") -> None:
|
|
20
|
+
super().__init__(message=f"{message} (Valid Value: {valid_value})", config_key=config_key)
|