logwell 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.
@@ -0,0 +1,216 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ # Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ # poetry.lock
109
+ # poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ # pdm.lock
116
+ # pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ # pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # Redis
135
+ *.rdb
136
+ *.aof
137
+ *.pid
138
+
139
+ # RabbitMQ
140
+ mnesia/
141
+ rabbitmq/
142
+ rabbitmq-data/
143
+
144
+ # ActiveMQ
145
+ activemq-data/
146
+
147
+ # SageMath parsed files
148
+ *.sage.py
149
+
150
+ # Environments
151
+ .env
152
+ .envrc
153
+ .venv
154
+ env/
155
+ venv/
156
+ ENV/
157
+ env.bak/
158
+ venv.bak/
159
+
160
+ # Spyder project settings
161
+ .spyderproject
162
+ .spyproject
163
+
164
+ # Rope project settings
165
+ .ropeproject
166
+
167
+ # mkdocs documentation
168
+ /site
169
+
170
+ # mypy
171
+ .mypy_cache/
172
+ .dmypy.json
173
+ dmypy.json
174
+
175
+ # Pyre type checker
176
+ .pyre/
177
+
178
+ # pytype static type analyzer
179
+ .pytype/
180
+
181
+ # Cython debug symbols
182
+ cython_debug/
183
+
184
+ # PyCharm
185
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
186
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
187
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
188
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
189
+ # .idea/
190
+
191
+ # Abstra
192
+ # Abstra is an AI-powered process automation framework.
193
+ # Ignore directories containing user credentials, local state, and settings.
194
+ # Learn more at https://abstra.io/docs
195
+ .abstra/
196
+
197
+ # Visual Studio Code
198
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
199
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
200
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
201
+ # you could uncomment the following to ignore the entire vscode folder
202
+ # .vscode/
203
+
204
+ # Ruff stuff:
205
+ .ruff_cache/
206
+
207
+ # PyPI configuration file
208
+ .pypirc
209
+
210
+ # Marimo
211
+ marimo/_static/
212
+ marimo/_lsp/
213
+ __marimo__/
214
+
215
+ # Streamlit
216
+ .streamlit/secrets.toml
logwell-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Logwell
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
logwell-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,284 @@
1
+ Metadata-Version: 2.4
2
+ Name: logwell
3
+ Version: 0.1.0
4
+ Summary: Official Python SDK for Logwell logging platform
5
+ Project-URL: Homepage, https://github.com/Divkix/Logwell
6
+ Project-URL: Documentation, https://github.com/Divkix/Logwell/tree/main/sdks/python#readme
7
+ Project-URL: Repository, https://github.com/Divkix/Logwell
8
+ Project-URL: Issues, https://github.com/Divkix/Logwell/issues
9
+ Author-email: Divkix <divkix@divkix.me>
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: logging,logs,logwell,observability,python
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.9
25
+ Requires-Dist: httpx>=0.25.0
26
+ Requires-Dist: typing-extensions>=4.0.0
27
+ Provides-Extra: dev
28
+ Requires-Dist: coverage[toml]>=7.0.0; extra == 'dev'
29
+ Requires-Dist: mypy>=1.8.0; extra == 'dev'
30
+ Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
31
+ Requires-Dist: pytest-cov>=4.1.0; extra == 'dev'
32
+ Requires-Dist: pytest>=8.0.0; extra == 'dev'
33
+ Requires-Dist: respx>=0.21.0; extra == 'dev'
34
+ Requires-Dist: ruff>=0.4.0; extra == 'dev'
35
+ Description-Content-Type: text/markdown
36
+
37
+ # Logwell Python SDK
38
+
39
+ Official Python SDK for the [Logwell](https://github.com/Divkix/Logwell) logging platform.
40
+
41
+ ## Installation
42
+
43
+ ```bash
44
+ pip install logwell
45
+ ```
46
+
47
+ ## Quick Start
48
+
49
+ ```python
50
+ import asyncio
51
+ from logwell import Logwell
52
+
53
+ # Initialize client
54
+ client = Logwell({
55
+ 'api_key': 'lw_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
56
+ 'endpoint': 'https://logs.example.com',
57
+ 'service': 'my-app',
58
+ })
59
+
60
+ # Log messages at different levels
61
+ client.debug('Debug message')
62
+ client.info('User logged in', {'user_id': '123'})
63
+ client.warn('Disk space low', {'available_gb': 5})
64
+ client.error('Failed to process request', {'request_id': 'abc'})
65
+ client.fatal('Database connection lost')
66
+
67
+ # Ensure logs are sent before exit
68
+ asyncio.run(client.shutdown())
69
+ ```
70
+
71
+ ## Configuration
72
+
73
+ | Option | Type | Default | Description |
74
+ |--------|------|---------|-------------|
75
+ | `api_key` | `str` | **required** | API key in format `lw_[32 chars]` |
76
+ | `endpoint` | `str` | **required** | Logwell server URL |
77
+ | `service` | `str` | `None` | Default service name for all logs |
78
+ | `batch_size` | `int` | `50` | Number of logs to batch before auto-flush |
79
+ | `flush_interval` | `float` | `5.0` | Seconds between auto-flushes |
80
+ | `max_queue_size` | `int` | `1000` | Maximum queue size before dropping oldest |
81
+ | `max_retries` | `int` | `3` | Retry attempts for failed requests |
82
+ | `capture_source_location` | `bool` | `False` | Capture file/line info |
83
+ | `on_error` | `Callable` | `None` | Error callback |
84
+ | `on_flush` | `Callable` | `None` | Flush callback |
85
+
86
+ ### Example with all options
87
+
88
+ ```python
89
+ from logwell import Logwell
90
+
91
+ def on_error(err):
92
+ print(f'Logging error: {err}')
93
+
94
+ def on_flush(count):
95
+ print(f'Flushed {count} logs')
96
+
97
+ client = Logwell({
98
+ 'api_key': 'lw_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
99
+ 'endpoint': 'https://logs.example.com',
100
+ 'service': 'my-app',
101
+ 'batch_size': 100,
102
+ 'flush_interval': 10.0,
103
+ 'max_queue_size': 5000,
104
+ 'max_retries': 5,
105
+ 'capture_source_location': True,
106
+ 'on_error': on_error,
107
+ 'on_flush': on_flush,
108
+ })
109
+ ```
110
+
111
+ ## API Reference
112
+
113
+ ### Logwell
114
+
115
+ The main client class.
116
+
117
+ #### Constructor
118
+
119
+ ```python
120
+ Logwell(config: LogwellConfig)
121
+ ```
122
+
123
+ #### Methods
124
+
125
+ | Method | Description |
126
+ |--------|-------------|
127
+ | `debug(message, metadata=None)` | Log at debug level |
128
+ | `info(message, metadata=None)` | Log at info level |
129
+ | `warn(message, metadata=None)` | Log at warning level |
130
+ | `error(message, metadata=None)` | Log at error level |
131
+ | `fatal(message, metadata=None)` | Log at fatal level |
132
+ | `log(entry)` | Log with explicit LogEntry |
133
+ | `flush()` | Async: Flush queued logs immediately |
134
+ | `shutdown()` | Async: Flush and stop the client |
135
+ | `child(metadata=None, service=None)` | Create child logger with context |
136
+ | `queue_size` | Property: Current queue size |
137
+
138
+ ### Child Loggers
139
+
140
+ Create child loggers to add persistent context:
141
+
142
+ ```python
143
+ # Create child logger with request context
144
+ request_logger = client.child({'request_id': 'abc-123'})
145
+ request_logger.info('Processing request') # Includes request_id
146
+
147
+ # Override service name
148
+ db_logger = client.child(service='my-app-db')
149
+ db_logger.info('Query executed', {'duration_ms': 45})
150
+ ```
151
+
152
+ ### Log Entry
153
+
154
+ ```python
155
+ from logwell import LogLevel
156
+
157
+ # Using log() with explicit entry
158
+ client.log({
159
+ 'level': 'info',
160
+ 'message': 'Custom log',
161
+ 'metadata': {'key': 'value'},
162
+ 'service': 'override-service',
163
+ 'timestamp': '2024-01-01T00:00:00Z', # Optional, auto-generated
164
+ })
165
+ ```
166
+
167
+ ### LogLevel
168
+
169
+ Available log levels: `debug`, `info`, `warn`, `error`, `fatal`
170
+
171
+ ### LogwellConfig
172
+
173
+ TypedDict with configuration options. See Configuration section above.
174
+
175
+ ### IngestResponse
176
+
177
+ Response from the server after flushing logs:
178
+
179
+ ```python
180
+ {
181
+ 'accepted': 50, # Logs accepted
182
+ 'rejected': 0, # Logs rejected (optional)
183
+ 'errors': [], # Error messages (optional)
184
+ }
185
+ ```
186
+
187
+ ## Error Handling
188
+
189
+ ### LogwellError
190
+
191
+ All SDK errors are wrapped in `LogwellError`:
192
+
193
+ ```python
194
+ from logwell import Logwell, LogwellError, LogwellErrorCode
195
+
196
+ try:
197
+ client = Logwell({'api_key': 'invalid', 'endpoint': 'https://example.com'})
198
+ except LogwellError as e:
199
+ print(e.message) # Human-readable message
200
+ print(e.code) # LogwellErrorCode enum
201
+ print(e.status_code) # HTTP status (if applicable)
202
+ print(e.retryable) # Whether operation can be retried
203
+ ```
204
+
205
+ ### Error Codes
206
+
207
+ | Code | Description |
208
+ |------|-------------|
209
+ | `INVALID_CONFIG` | Invalid configuration value |
210
+ | `NETWORK_ERROR` | Network connectivity or timeout |
211
+ | `UNAUTHORIZED` | Invalid or expired API key (401) |
212
+ | `VALIDATION_ERROR` | Invalid request data |
213
+ | `RATE_LIMITED` | Too many requests (429) |
214
+ | `SERVER_ERROR` | Server-side error (5xx) |
215
+ | `QUEUE_OVERFLOW` | Queue exceeded max size |
216
+
217
+ ### Error Callback
218
+
219
+ Handle errors without try/catch:
220
+
221
+ ```python
222
+ def handle_error(err: Exception):
223
+ if isinstance(err, LogwellError):
224
+ if err.code == LogwellErrorCode.NETWORK_ERROR:
225
+ print('Network issue, logs will be retried')
226
+ elif err.code == LogwellErrorCode.QUEUE_OVERFLOW:
227
+ print('Queue full, some logs dropped')
228
+
229
+ client = Logwell({
230
+ 'api_key': 'lw_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
231
+ 'endpoint': 'https://logs.example.com',
232
+ 'on_error': handle_error,
233
+ })
234
+ ```
235
+
236
+ ## Async Usage
237
+
238
+ The SDK uses async for flush and shutdown operations:
239
+
240
+ ```python
241
+ import asyncio
242
+ from logwell import Logwell
243
+
244
+ async def main():
245
+ client = Logwell({
246
+ 'api_key': 'lw_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
247
+ 'endpoint': 'https://logs.example.com',
248
+ })
249
+
250
+ client.info('Starting app')
251
+
252
+ # Manual flush
253
+ response = await client.flush()
254
+ print(f'Sent {response["accepted"]} logs')
255
+
256
+ # Shutdown gracefully
257
+ await client.shutdown()
258
+
259
+ asyncio.run(main())
260
+ ```
261
+
262
+ ## Source Location Capture
263
+
264
+ Enable automatic file/line capture:
265
+
266
+ ```python
267
+ client = Logwell({
268
+ 'api_key': 'lw_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
269
+ 'endpoint': 'https://logs.example.com',
270
+ 'capture_source_location': True,
271
+ })
272
+
273
+ client.info('This log includes file and line number')
274
+ # Log includes: source_file='app.py', line_number=42
275
+ ```
276
+
277
+ ## Requirements
278
+
279
+ - Python 3.9+
280
+ - httpx >= 0.25.0
281
+
282
+ ## License
283
+
284
+ MIT License - see [LICENSE](LICENSE) for details.