viveka-grantha 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.
- viveka_grantha-0.1.0/LICENSE.txt +110 -0
- viveka_grantha-0.1.0/PKG-INFO +427 -0
- viveka_grantha-0.1.0/README.md +287 -0
- viveka_grantha-0.1.0/pyproject.toml +49 -0
- viveka_grantha-0.1.0/setup.cfg +4 -0
- viveka_grantha-0.1.0/viveka_common/__init__.py +20 -0
- viveka_grantha-0.1.0/viveka_common/cache/__init__.py +11 -0
- viveka_grantha-0.1.0/viveka_common/cache/redis_cache_service.py +79 -0
- viveka_grantha-0.1.0/viveka_common/cache/viveka_cache_config.py +9 -0
- viveka_grantha-0.1.0/viveka_common/cache/viveka_cache_manager.py +77 -0
- viveka_grantha-0.1.0/viveka_common/cache/viveka_cache_service.py +25 -0
- viveka_grantha-0.1.0/viveka_common/config/__init__.py +4 -0
- viveka_grantha-0.1.0/viveka_common/config/config_loader.py +110 -0
- viveka_grantha-0.1.0/viveka_common/config/config_service.py +191 -0
- viveka_grantha-0.1.0/viveka_common/log/__init__.py +4 -0
- viveka_grantha-0.1.0/viveka_common/log/viveka_log_manager.py +170 -0
- viveka_grantha-0.1.0/viveka_common/log/viveka_logger.py +28 -0
- viveka_grantha-0.1.0/viveka_common/py.typed +0 -0
- viveka_grantha-0.1.0/viveka_grantha.egg-info/PKG-INFO +427 -0
- viveka_grantha-0.1.0/viveka_grantha.egg-info/SOURCES.txt +21 -0
- viveka_grantha-0.1.0/viveka_grantha.egg-info/dependency_links.txt +1 -0
- viveka_grantha-0.1.0/viveka_grantha.egg-info/requires.txt +9 -0
- viveka_grantha-0.1.0/viveka_grantha.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
VIVEKASUTRA PROPRIETARY SOFTWARE LICENSE
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 VivekaSutra. All rights reserved.
|
|
4
|
+
https://vivekasutra.com/
|
|
5
|
+
|
|
6
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
7
|
+
IMPORTANT: READ THIS LICENSE CAREFULLY BEFORE DOWNLOADING,
|
|
8
|
+
INSTALLING, OR USING THIS SOFTWARE.
|
|
9
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
10
|
+
|
|
11
|
+
By downloading, installing, or using this software ("viveka-grantha"),
|
|
12
|
+
you agree to be bound by the terms of this license agreement.
|
|
13
|
+
If you do not agree, do not download, install, or use this software.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
1. GRANT OF LICENSE
|
|
17
|
+
VivekaSutra grants you a limited, non-exclusive, non-transferable,
|
|
18
|
+
royalty-free license to download and use this software solely for
|
|
19
|
+
your personal or internal business purposes.
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
2. RESTRICTIONS
|
|
23
|
+
You may NOT:
|
|
24
|
+
a) Copy, modify, merge, or create derivative works of this software.
|
|
25
|
+
b) Distribute, sell, sublicense, rent, lease, or transfer this
|
|
26
|
+
software or any rights in it to any third party.
|
|
27
|
+
c) Reverse engineer, decompile, disassemble, or attempt to derive
|
|
28
|
+
the source code of this software.
|
|
29
|
+
d) Remove, alter, or obscure any proprietary notices, labels,
|
|
30
|
+
or markings on this software.
|
|
31
|
+
e) Use this software to build a competing product or service.
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
3. INTELLECTUAL PROPERTY
|
|
35
|
+
This software and all copies thereof are proprietary to VivekaSutra.
|
|
36
|
+
All title, ownership rights, and intellectual property rights in and
|
|
37
|
+
to this software remain exclusively with VivekaSutra. This license
|
|
38
|
+
does not grant you any rights to trademarks, service marks, or trade
|
|
39
|
+
names of VivekaSutra.
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
4. NO WARRANTY
|
|
43
|
+
THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
|
|
44
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
45
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
|
46
|
+
NON-INFRINGEMENT.
|
|
47
|
+
|
|
48
|
+
VIVEKASUTRA DOES NOT WARRANT THAT:
|
|
49
|
+
a) THE SOFTWARE WILL MEET YOUR REQUIREMENTS.
|
|
50
|
+
b) THE SOFTWARE WILL OPERATE UNINTERRUPTED OR ERROR-FREE.
|
|
51
|
+
c) ANY ERRORS IN THE SOFTWARE WILL BE CORRECTED.
|
|
52
|
+
d) THE SOFTWARE IS COMPATIBLE WITH YOUR SYSTEMS OR ENVIRONMENT.
|
|
53
|
+
|
|
54
|
+
YOU ASSUME ALL RISK ASSOCIATED WITH THE USE OF THIS SOFTWARE.
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
5. LIMITATION OF LIABILITY
|
|
58
|
+
TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL
|
|
59
|
+
VIVEKASUTRA, ITS DIRECTORS, EMPLOYEES, PARTNERS, AGENTS, SUPPLIERS,
|
|
60
|
+
OR AFFILIATES BE LIABLE FOR ANY:
|
|
61
|
+
|
|
62
|
+
a) DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
63
|
+
CONSEQUENTIAL DAMAGES.
|
|
64
|
+
b) LOSS OF PROFITS, REVENUE, DATA, BUSINESS, OR GOODWILL.
|
|
65
|
+
c) BUSINESS INTERRUPTION OR LOSS OF BUSINESS OPPORTUNITY.
|
|
66
|
+
d) COST OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES.
|
|
67
|
+
e) ANY OTHER COMMERCIAL OR ECONOMIC LOSS.
|
|
68
|
+
|
|
69
|
+
THIS LIMITATION APPLIES REGARDLESS OF WHETHER SUCH DAMAGES ARISE
|
|
70
|
+
FROM CONTRACT, TORT, NEGLIGENCE, STRICT LIABILITY, OR ANY OTHER
|
|
71
|
+
LEGAL THEORY, AND EVEN IF VIVEKASUTRA HAS BEEN ADVISED OF THE
|
|
72
|
+
POSSIBILITY OF SUCH DAMAGES.
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
6. INDEMNIFICATION
|
|
76
|
+
You agree to indemnify, defend, and hold harmless VivekaSutra and
|
|
77
|
+
its affiliates from and against any claims, liabilities, damages,
|
|
78
|
+
losses, and expenses (including legal fees) arising out of or in
|
|
79
|
+
connection with your use of this software or your violation of
|
|
80
|
+
this license.
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
7. TERMINATION
|
|
84
|
+
This license is effective until terminated. Your rights under this
|
|
85
|
+
license will terminate automatically and without notice from
|
|
86
|
+
VivekaSutra if you fail to comply with any of its terms and
|
|
87
|
+
conditions. Upon termination, you must immediately cease all use
|
|
88
|
+
of this software and destroy all copies in your possession.
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
8. GOVERNING LAW
|
|
92
|
+
This license shall be governed by and construed in accordance with
|
|
93
|
+
applicable laws. Any disputes arising under this license shall be
|
|
94
|
+
subject to the exclusive jurisdiction of the competent courts.
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
9. ENTIRE AGREEMENT
|
|
98
|
+
This license constitutes the entire agreement between you and
|
|
99
|
+
VivekaSutra with respect to this software and supersedes all prior
|
|
100
|
+
or contemporaneous understandings, agreements, or representations.
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
104
|
+
For licensing inquiries or permissions beyond the scope of this
|
|
105
|
+
license, please contact us at: https://vivekasutra.com/
|
|
106
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
107
|
+
|
|
108
|
+
VivekaSutra
|
|
109
|
+
https://vivekasutra.com/
|
|
110
|
+
Copyright (c) 2025. All rights reserved.
|
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: viveka-grantha
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Core shared library for Viveka — config, logging, and async cache management
|
|
5
|
+
License: VIVEKASUTRA PROPRIETARY SOFTWARE LICENSE
|
|
6
|
+
|
|
7
|
+
Copyright (c) 2025 VivekaSutra. All rights reserved.
|
|
8
|
+
https://vivekasutra.com/
|
|
9
|
+
|
|
10
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
11
|
+
IMPORTANT: READ THIS LICENSE CAREFULLY BEFORE DOWNLOADING,
|
|
12
|
+
INSTALLING, OR USING THIS SOFTWARE.
|
|
13
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
14
|
+
|
|
15
|
+
By downloading, installing, or using this software ("viveka-grantha"),
|
|
16
|
+
you agree to be bound by the terms of this license agreement.
|
|
17
|
+
If you do not agree, do not download, install, or use this software.
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
1. GRANT OF LICENSE
|
|
21
|
+
VivekaSutra grants you a limited, non-exclusive, non-transferable,
|
|
22
|
+
royalty-free license to download and use this software solely for
|
|
23
|
+
your personal or internal business purposes.
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
2. RESTRICTIONS
|
|
27
|
+
You may NOT:
|
|
28
|
+
a) Copy, modify, merge, or create derivative works of this software.
|
|
29
|
+
b) Distribute, sell, sublicense, rent, lease, or transfer this
|
|
30
|
+
software or any rights in it to any third party.
|
|
31
|
+
c) Reverse engineer, decompile, disassemble, or attempt to derive
|
|
32
|
+
the source code of this software.
|
|
33
|
+
d) Remove, alter, or obscure any proprietary notices, labels,
|
|
34
|
+
or markings on this software.
|
|
35
|
+
e) Use this software to build a competing product or service.
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
3. INTELLECTUAL PROPERTY
|
|
39
|
+
This software and all copies thereof are proprietary to VivekaSutra.
|
|
40
|
+
All title, ownership rights, and intellectual property rights in and
|
|
41
|
+
to this software remain exclusively with VivekaSutra. This license
|
|
42
|
+
does not grant you any rights to trademarks, service marks, or trade
|
|
43
|
+
names of VivekaSutra.
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
4. NO WARRANTY
|
|
47
|
+
THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
|
|
48
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
49
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
|
50
|
+
NON-INFRINGEMENT.
|
|
51
|
+
|
|
52
|
+
VIVEKASUTRA DOES NOT WARRANT THAT:
|
|
53
|
+
a) THE SOFTWARE WILL MEET YOUR REQUIREMENTS.
|
|
54
|
+
b) THE SOFTWARE WILL OPERATE UNINTERRUPTED OR ERROR-FREE.
|
|
55
|
+
c) ANY ERRORS IN THE SOFTWARE WILL BE CORRECTED.
|
|
56
|
+
d) THE SOFTWARE IS COMPATIBLE WITH YOUR SYSTEMS OR ENVIRONMENT.
|
|
57
|
+
|
|
58
|
+
YOU ASSUME ALL RISK ASSOCIATED WITH THE USE OF THIS SOFTWARE.
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
5. LIMITATION OF LIABILITY
|
|
62
|
+
TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL
|
|
63
|
+
VIVEKASUTRA, ITS DIRECTORS, EMPLOYEES, PARTNERS, AGENTS, SUPPLIERS,
|
|
64
|
+
OR AFFILIATES BE LIABLE FOR ANY:
|
|
65
|
+
|
|
66
|
+
a) DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
67
|
+
CONSEQUENTIAL DAMAGES.
|
|
68
|
+
b) LOSS OF PROFITS, REVENUE, DATA, BUSINESS, OR GOODWILL.
|
|
69
|
+
c) BUSINESS INTERRUPTION OR LOSS OF BUSINESS OPPORTUNITY.
|
|
70
|
+
d) COST OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES.
|
|
71
|
+
e) ANY OTHER COMMERCIAL OR ECONOMIC LOSS.
|
|
72
|
+
|
|
73
|
+
THIS LIMITATION APPLIES REGARDLESS OF WHETHER SUCH DAMAGES ARISE
|
|
74
|
+
FROM CONTRACT, TORT, NEGLIGENCE, STRICT LIABILITY, OR ANY OTHER
|
|
75
|
+
LEGAL THEORY, AND EVEN IF VIVEKASUTRA HAS BEEN ADVISED OF THE
|
|
76
|
+
POSSIBILITY OF SUCH DAMAGES.
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
6. INDEMNIFICATION
|
|
80
|
+
You agree to indemnify, defend, and hold harmless VivekaSutra and
|
|
81
|
+
its affiliates from and against any claims, liabilities, damages,
|
|
82
|
+
losses, and expenses (including legal fees) arising out of or in
|
|
83
|
+
connection with your use of this software or your violation of
|
|
84
|
+
this license.
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
7. TERMINATION
|
|
88
|
+
This license is effective until terminated. Your rights under this
|
|
89
|
+
license will terminate automatically and without notice from
|
|
90
|
+
VivekaSutra if you fail to comply with any of its terms and
|
|
91
|
+
conditions. Upon termination, you must immediately cease all use
|
|
92
|
+
of this software and destroy all copies in your possession.
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
8. GOVERNING LAW
|
|
96
|
+
This license shall be governed by and construed in accordance with
|
|
97
|
+
applicable laws. Any disputes arising under this license shall be
|
|
98
|
+
subject to the exclusive jurisdiction of the competent courts.
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
9. ENTIRE AGREEMENT
|
|
102
|
+
This license constitutes the entire agreement between you and
|
|
103
|
+
VivekaSutra with respect to this software and supersedes all prior
|
|
104
|
+
or contemporaneous understandings, agreements, or representations.
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
108
|
+
For licensing inquiries or permissions beyond the scope of this
|
|
109
|
+
license, please contact us at: https://vivekasutra.com/
|
|
110
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
111
|
+
|
|
112
|
+
VivekaSutra
|
|
113
|
+
https://vivekasutra.com/
|
|
114
|
+
Copyright (c) 2025. All rights reserved.
|
|
115
|
+
|
|
116
|
+
Project-URL: Homepage, https://vivekasutra.com/
|
|
117
|
+
Project-URL: Source, https://github.com/vivekasutra/viveka-grantha
|
|
118
|
+
Keywords: config,logging,cache,redis,async,viveka
|
|
119
|
+
Classifier: Development Status :: 3 - Alpha
|
|
120
|
+
Classifier: Intended Audience :: Developers
|
|
121
|
+
Classifier: License :: Other/Proprietary License
|
|
122
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
123
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
124
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
125
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
126
|
+
Classifier: Framework :: AsyncIO
|
|
127
|
+
Classifier: Typing :: Typed
|
|
128
|
+
Requires-Python: >=3.11
|
|
129
|
+
Description-Content-Type: text/markdown
|
|
130
|
+
License-File: LICENSE.txt
|
|
131
|
+
Requires-Dist: redis>=5.0
|
|
132
|
+
Requires-Dist: hiredis>=2.0
|
|
133
|
+
Requires-Dist: aiohttp>=3.9
|
|
134
|
+
Provides-Extra: dev
|
|
135
|
+
Requires-Dist: build; extra == "dev"
|
|
136
|
+
Requires-Dist: twine; extra == "dev"
|
|
137
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
138
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
|
|
139
|
+
Dynamic: license-file
|
|
140
|
+
|
|
141
|
+
# viveka-grantha
|
|
142
|
+
|
|
143
|
+
Core shared library for the Viveka platform — provides configuration management, structured logging, and async cache management as reusable infrastructure components.
|
|
144
|
+
|
|
145
|
+
Developed by [VivekaSutra](https://vivekasutra.com/)
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## Overview
|
|
150
|
+
|
|
151
|
+
viveka-grantha is the foundation layer that all Viveka services depend on. It solves three cross-cutting concerns so individual services don't have to:
|
|
152
|
+
|
|
153
|
+
| Module | What it does |
|
|
154
|
+
|---|---|
|
|
155
|
+
| `viveka_common.config` | Reads config from `config.ini` and environment variables with a unified API |
|
|
156
|
+
| `viveka_common.log` | Singleton logging manager with console and rotating file handlers |
|
|
157
|
+
| `viveka_common.cache` | Async Redis cache with a pluggable backend interface |
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## Installation
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
pip install viveka-grantha
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## Configuration
|
|
170
|
+
|
|
171
|
+
### Structure
|
|
172
|
+
|
|
173
|
+
viveka-grantha reads from a `config.ini` file using `section.key` dot notation.
|
|
174
|
+
|
|
175
|
+
`config.ini`:
|
|
176
|
+
|
|
177
|
+
```ini
|
|
178
|
+
[app]
|
|
179
|
+
name = my-service
|
|
180
|
+
env = production
|
|
181
|
+
|
|
182
|
+
[logging]
|
|
183
|
+
level = INFO
|
|
184
|
+
file_enabled = true
|
|
185
|
+
file_path = logs/app.log
|
|
186
|
+
console_enabled = true
|
|
187
|
+
|
|
188
|
+
[cache]
|
|
189
|
+
enabled = true
|
|
190
|
+
backend = redis
|
|
191
|
+
url = redis://localhost:6379/0
|
|
192
|
+
default_ttl = 3600
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Priority order
|
|
196
|
+
|
|
197
|
+
When you call `config.get("database.url")`, the service checks in this order:
|
|
198
|
+
|
|
199
|
+
1. Environment variable — `DATABASE_URL`
|
|
200
|
+
2. `config.ini` — `[database] url = ...`
|
|
201
|
+
3. Default value you provide
|
|
202
|
+
|
|
203
|
+
This means you can override any config value with an environment variable without touching the file — useful for Docker and cloud deployments.
|
|
204
|
+
|
|
205
|
+
### Usage
|
|
206
|
+
|
|
207
|
+
```python
|
|
208
|
+
from viveka_common.config import ConfigService
|
|
209
|
+
|
|
210
|
+
config = ConfigService() # reads config.ini from current directory
|
|
211
|
+
config = ConfigService("path/to/config.ini") # custom path
|
|
212
|
+
|
|
213
|
+
# Get values
|
|
214
|
+
db_url = config.get("database.url")
|
|
215
|
+
port = config.get("api.port", default=8000, data_type=int)
|
|
216
|
+
debug = config.get("app.debug", default=False, data_type=bool)
|
|
217
|
+
hosts = config.get("app.allowed_hosts", data_type=list) # comma-separated in ini
|
|
218
|
+
|
|
219
|
+
# Read from environment variable directly
|
|
220
|
+
token = config.get_env_variable("api.secret_key") # reads API_SECRET_KEY env var
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
`ConfigService` is a singleton — calling `ConfigService()` anywhere in the application returns the same instance initialized at startup.
|
|
224
|
+
|
|
225
|
+
### Supported data types
|
|
226
|
+
|
|
227
|
+
| Type | Config.ini example | Result |
|
|
228
|
+
|---|---|---|
|
|
229
|
+
| `str` (default) | `name = viveka` | `"viveka"` |
|
|
230
|
+
| `int` | `port = 8080` | `8080` |
|
|
231
|
+
| `float` | `timeout = 3.5` | `3.5` |
|
|
232
|
+
| `bool` | `debug = true` | `True` |
|
|
233
|
+
| `list` | `hosts = a.com, b.com` | `["a.com", "b.com"]` |
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## Logging
|
|
238
|
+
|
|
239
|
+
### Setup
|
|
240
|
+
|
|
241
|
+
Initialize once at application startup before any other code runs:
|
|
242
|
+
|
|
243
|
+
```python
|
|
244
|
+
from viveka_common.log import VivekaLogManager, VivekaLoggingConfig
|
|
245
|
+
|
|
246
|
+
VivekaLogManager.init(VivekaLoggingConfig(
|
|
247
|
+
level = "INFO",
|
|
248
|
+
console_enabled = True,
|
|
249
|
+
file_enabled = True,
|
|
250
|
+
file_path = "logs/app.log",
|
|
251
|
+
file_max_bytes = 10_485_760, # 10 MB
|
|
252
|
+
file_backup_count = 5,
|
|
253
|
+
))
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### Getting a logger
|
|
257
|
+
|
|
258
|
+
Any class or module gets its own named logger:
|
|
259
|
+
|
|
260
|
+
```python
|
|
261
|
+
from viveka_common.log import VivekaLogManager
|
|
262
|
+
|
|
263
|
+
_logger = VivekaLogManager.get_instance(__name__)
|
|
264
|
+
|
|
265
|
+
class UserService:
|
|
266
|
+
def create_user(self, name: str):
|
|
267
|
+
_logger.info(f"Creating user: {name}")
|
|
268
|
+
_logger.debug("Debug details here")
|
|
269
|
+
_logger.error("Something went wrong", exc_info=True)
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### VivekaLoggingConfig options
|
|
273
|
+
|
|
274
|
+
| Field | Default | Description |
|
|
275
|
+
|---|---|---|
|
|
276
|
+
| `level` | `"INFO"` | Root log level — DEBUG, INFO, WARNING, ERROR, CRITICAL |
|
|
277
|
+
| `format` | standard format | Log line format string |
|
|
278
|
+
| `console_enabled` | `True` | Print logs to stdout |
|
|
279
|
+
| `console_level` | inherits `level` | Override level for console only |
|
|
280
|
+
| `file_enabled` | `True` | Write logs to a rotating file |
|
|
281
|
+
| `file_path` | `"logs/viveka.log"` | Log file path |
|
|
282
|
+
| `file_level` | inherits `level` | Override level for file only |
|
|
283
|
+
| `file_max_bytes` | `10485760` (10 MB) | Max size before rotation |
|
|
284
|
+
| `file_backup_count` | `5` | Number of rotated files to keep |
|
|
285
|
+
|
|
286
|
+
### Notes
|
|
287
|
+
|
|
288
|
+
- `VivekaLogManager` is a singleton. `init()` only runs once — subsequent calls are no-ops unless you pass a new config.
|
|
289
|
+
- `get_instance()` can be called before `init()` — it auto-initializes with `INFO` level defaults.
|
|
290
|
+
- Rotating file handler prevents log files from growing unbounded.
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
## Cache
|
|
295
|
+
|
|
296
|
+
### Setup
|
|
297
|
+
|
|
298
|
+
Initialize once at application startup:
|
|
299
|
+
|
|
300
|
+
```python
|
|
301
|
+
from viveka_common.cache import VivekaCacheConfig, RedisCacheService, VivekaCacheManager
|
|
302
|
+
|
|
303
|
+
config = VivekaCacheConfig(
|
|
304
|
+
enabled = True,
|
|
305
|
+
url = "redis://localhost:6379/0",
|
|
306
|
+
default_ttl = 3600,
|
|
307
|
+
)
|
|
308
|
+
|
|
309
|
+
service = RedisCacheService(config)
|
|
310
|
+
VivekaCacheManager.init(service)
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
To disable caching entirely without changing call sites:
|
|
314
|
+
|
|
315
|
+
```python
|
|
316
|
+
VivekaCacheConfig(enabled=False) # all cache ops become silent no-ops
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
### Using the cache manager
|
|
320
|
+
|
|
321
|
+
`VivekaCacheManager` is the single access point for all cache operations across the application. All methods are async.
|
|
322
|
+
|
|
323
|
+
```python
|
|
324
|
+
from viveka_common.cache import VivekaCacheManager
|
|
325
|
+
|
|
326
|
+
# Store a value (ttl in seconds, optional — uses default_ttl if omitted)
|
|
327
|
+
await VivekaCacheManager.set("user:123", {"id": 123, "name": "Arjun"}, ttl=3600)
|
|
328
|
+
|
|
329
|
+
# Retrieve a value
|
|
330
|
+
user = await VivekaCacheManager.get("user:123") # returns None on miss
|
|
331
|
+
|
|
332
|
+
# Delete a single key
|
|
333
|
+
await VivekaCacheManager.delete("user:123")
|
|
334
|
+
|
|
335
|
+
# Delete all keys matching a pattern (used by @cache_evict)
|
|
336
|
+
await VivekaCacheManager.delete_pattern("user:*")
|
|
337
|
+
|
|
338
|
+
# Health check
|
|
339
|
+
is_alive = await VivekaCacheManager.ping()
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
If the cache backend is down, every operation logs an error and returns a safe default (`None` / `False`) — business logic is never interrupted.
|
|
343
|
+
|
|
344
|
+
### Custom cache backend
|
|
345
|
+
|
|
346
|
+
`VivekaCacheService` is an abstract interface. You can implement your own backend (Memcached, in-memory, etc.) and plug it in:
|
|
347
|
+
|
|
348
|
+
```python
|
|
349
|
+
from viveka_common.cache import VivekaCacheService, VivekaCacheManager
|
|
350
|
+
|
|
351
|
+
class InMemoryCacheService(VivekaCacheService):
|
|
352
|
+
def __init__(self):
|
|
353
|
+
self._store = {}
|
|
354
|
+
|
|
355
|
+
async def get(self, key): return self._store.get(key)
|
|
356
|
+
async def set(self, key, value, ttl=None): self._store[key] = value; return True
|
|
357
|
+
async def delete(self, key): self._store.pop(key, None); return True
|
|
358
|
+
async def delete_pattern(self, pattern): ...
|
|
359
|
+
async def ping(self): return True
|
|
360
|
+
|
|
361
|
+
VivekaCacheManager.init(InMemoryCacheService())
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
---
|
|
365
|
+
|
|
366
|
+
## Full startup example
|
|
367
|
+
|
|
368
|
+
```python
|
|
369
|
+
from viveka_common.config import ConfigService
|
|
370
|
+
from viveka_common.log import VivekaLogManager, VivekaLoggingConfig
|
|
371
|
+
from viveka_common.cache import VivekaCacheConfig, RedisCacheService, VivekaCacheManager
|
|
372
|
+
|
|
373
|
+
def bootstrap():
|
|
374
|
+
# 1. Config
|
|
375
|
+
config = ConfigService("config.ini")
|
|
376
|
+
|
|
377
|
+
# 2. Logging
|
|
378
|
+
VivekaLogManager.init(VivekaLoggingConfig(
|
|
379
|
+
level = config.get("logging.level", default="INFO"),
|
|
380
|
+
file_path = config.get("logging.file_path", default="logs/app.log"),
|
|
381
|
+
))
|
|
382
|
+
|
|
383
|
+
# 3. Cache
|
|
384
|
+
cache_config = VivekaCacheConfig(
|
|
385
|
+
enabled = config.get("cache.enabled", default=False, data_type=bool),
|
|
386
|
+
url = config.get("cache.url", default="redis://localhost:6379/0"),
|
|
387
|
+
default_ttl = config.get("cache.default_ttl", default=3600, data_type=int),
|
|
388
|
+
)
|
|
389
|
+
VivekaCacheManager.init(RedisCacheService(cache_config))
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
---
|
|
393
|
+
|
|
394
|
+
## Dependencies
|
|
395
|
+
|
|
396
|
+
| Package | Role |
|
|
397
|
+
|---|---|
|
|
398
|
+
| `redis` | Async Redis client (`redis.asyncio`) |
|
|
399
|
+
| `hiredis` | High-performance Redis protocol parser |
|
|
400
|
+
| `aiohttp` | Async HTTP client for service-to-service calls |
|
|
401
|
+
|
|
402
|
+
---
|
|
403
|
+
|
|
404
|
+
## Part of the Viveka Platform
|
|
405
|
+
|
|
406
|
+
viveka-grantha is the foundation layer of the Viveka ecosystem:
|
|
407
|
+
|
|
408
|
+
- **viveka-grantha** — config, logging, cache ← you are here
|
|
409
|
+
- **viveka-kosha** — async database / ORM layer (depends on viveka-grantha)
|
|
410
|
+
|
|
411
|
+
Developed and maintained by [VivekaSutra](https://vivekasutra.com/)
|
|
412
|
+
|
|
413
|
+
---
|
|
414
|
+
|
|
415
|
+
## License
|
|
416
|
+
|
|
417
|
+
Copyright (c) 2025 VivekaSutra. All rights reserved.
|
|
418
|
+
|
|
419
|
+
This software is distributed under the **VivekaSutra Proprietary Software License**.
|
|
420
|
+
|
|
421
|
+
- Free to download and use for personal or commercial purposes
|
|
422
|
+
- Modification, redistribution, and reverse engineering are not permitted
|
|
423
|
+
- Provided "AS IS" — no warranty of any kind
|
|
424
|
+
- VivekaSutra is not liable for any damages arising from use
|
|
425
|
+
|
|
426
|
+
See [LICENSE.txt](LICENSE.txt) for the full license text.
|
|
427
|
+
For licensing inquiries visit [vivekasutra.com](https://vivekasutra.com/)
|