ddutils 0.4.0__tar.gz → 0.4.1__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.
- ddutils-0.4.0/README.md → ddutils-0.4.1/PKG-INFO +48 -9
- ddutils-0.4.0/PKG-INFO → ddutils-0.4.1/README.md +30 -27
- {ddutils-0.4.0 → ddutils-0.4.1}/ddutils/connections.py +44 -3
- {ddutils-0.4.0 → ddutils-0.4.1}/pyproject.toml +19 -2
- {ddutils-0.4.0 → ddutils-0.4.1}/pyproject.toml.orig +3 -3
- {ddutils-0.4.0 → ddutils-0.4.1}/LICENSE +0 -0
- {ddutils-0.4.0 → ddutils-0.4.1}/ddutils/__init__.py +0 -0
- {ddutils-0.4.0 → ddutils-0.4.1}/ddutils/annotation_helpers.py +0 -0
- {ddutils-0.4.0 → ddutils-0.4.1}/ddutils/class_helpers.py +0 -0
- {ddutils-0.4.0 → ddutils-0.4.1}/ddutils/context_helpers.py +0 -0
- {ddutils-0.4.0 → ddutils-0.4.1}/ddutils/convertors.py +0 -0
- {ddutils-0.4.0 → ddutils-0.4.1}/ddutils/datetime_helpers.py +0 -0
- {ddutils-0.4.0 → ddutils-0.4.1}/ddutils/feature_flags.py +0 -0
- {ddutils-0.4.0 → ddutils-0.4.1}/ddutils/function_exceptions_extractor.py +0 -0
- {ddutils-0.4.0 → ddutils-0.4.1}/ddutils/function_helpers.py +0 -0
- {ddutils-0.4.0 → ddutils-0.4.1}/ddutils/module_getter.py +0 -0
- {ddutils-0.4.0 → ddutils-0.4.1}/ddutils/object_getter.py +0 -0
- {ddutils-0.4.0 → ddutils-0.4.1}/ddutils/py.typed +0 -0
- {ddutils-0.4.0 → ddutils-0.4.1}/ddutils/safe_decorators.py +0 -0
- {ddutils-0.4.0 → ddutils-0.4.1}/ddutils/scoped_registry.py +0 -0
- {ddutils-0.4.0 → ddutils-0.4.1}/ddutils/sequence_helpers.py +0 -0
- {ddutils-0.4.0 → ddutils-0.4.1}/ddutils/value_helpers.py +0 -0
|
@@ -1,4 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ddutils
|
|
3
|
+
Version: 0.4.1
|
|
4
|
+
Summary: Shared utilities of the dd libraries: annotation and class helpers, convertors, scoped registries, connection factories and feature flags
|
|
5
|
+
Keywords: python,ddutils,utils,helpers,type hints,type annotations,introspection,generics,scoped registry,context scope,connection manager,connection factory,feature flags,feature toggle,retry,safe call,decorators,convertors,asyncio
|
|
6
|
+
Author: davyddd
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
14
|
+
Classifier: Typing :: Typed
|
|
15
|
+
Requires-Python: >=3.11, <3.15
|
|
16
|
+
Project-URL: Repository, https://github.com/davyddd/ddutils
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# ddutils
|
|
2
20
|
|
|
3
21
|
[](https://pypi.python.org/pypi/ddutils)
|
|
4
22
|
[](https://pepy.tech/project/ddutils)
|
|
@@ -6,8 +24,7 @@
|
|
|
6
24
|
[](https://app.codecov.io/github/davyddd/ddutils)
|
|
7
25
|
[](https://github.com/davyddd/ddutils/blob/main/LICENSE)
|
|
8
26
|
|
|
9
|
-
|
|
10
|
-
It focuses on type safety, robustness, and runtime introspection — all without external dependencies.
|
|
27
|
+
Shared utilities of the dd libraries: annotation and class helpers, convertors, scoped registries, connection factories and feature flags
|
|
11
28
|
|
|
12
29
|
## Installation
|
|
13
30
|
|
|
@@ -16,14 +33,9 @@ Install the library using pip:
|
|
|
16
33
|
pip install ddutils
|
|
17
34
|
```
|
|
18
35
|
|
|
19
|
-
## Compatibility
|
|
20
|
-
|
|
21
|
-
Python 3.11 to 3.14, no runtime dependencies. What changed in each release, breaking changes included, is in the
|
|
22
|
-
[GitHub releases](https://github.com/davyddd/ddutils/releases).
|
|
23
|
-
|
|
24
36
|
## Development
|
|
25
37
|
|
|
26
|
-
The project runs entirely in Docker.
|
|
38
|
+
The project runs entirely in Docker. Requires Docker and [Fabric](https://www.fabfile.org/) on the host:
|
|
27
39
|
|
|
28
40
|
```bash
|
|
29
41
|
fab build # build the dev image
|
|
@@ -36,6 +48,15 @@ fab bash # bash inside the container
|
|
|
36
48
|
This project was generated from [dd-lib-stub](https://github.com/davyddd/dd-lib-stub);
|
|
37
49
|
run `uvx copier update` to pull in template updates.
|
|
38
50
|
|
|
51
|
+
## Compatibility
|
|
52
|
+
|
|
53
|
+
Python 3.11 to 3.14. What changed in each release, breaking changes included,
|
|
54
|
+
is in the [GitHub releases](https://github.com/davyddd/ddutils/releases).
|
|
55
|
+
|
|
56
|
+
<!-- The sections below are the library's own; copier update leaves them alone -->
|
|
57
|
+
|
|
58
|
+
No runtime dependencies. The tests need no external services.
|
|
59
|
+
|
|
39
60
|
## Type Annotation Helpers
|
|
40
61
|
|
|
41
62
|
Utilities for inspecting and working with Python type hints and generic types.
|
|
@@ -584,6 +605,24 @@ async with atomic(alias=PostgresDB.REPLICA) as session:
|
|
|
584
605
|
await clickhouse.close()
|
|
585
606
|
```
|
|
586
607
|
|
|
608
|
+
### connection_proxy
|
|
609
|
+
|
|
610
|
+
Some libraries want a connection object at construction and keep it for the life of the process: a rate limiter's
|
|
611
|
+
bucket, a lock implementation. `connection_proxy(factory, *, alias=None)` returns a `ConnectionProxy` typed as the
|
|
612
|
+
connection it stands in for; every method call borrows the connection from the factory for that one call and keeps
|
|
613
|
+
nothing of it, the way a ddsql adapter or a ddredis lock does by hand. A sync method is called inside the borrow as
|
|
614
|
+
well and its result returned as is.
|
|
615
|
+
|
|
616
|
+
```python
|
|
617
|
+
from ddutils.connections import connection_proxy
|
|
618
|
+
|
|
619
|
+
bucket = await RedisBucket.init(rates, redis=connection_proxy(redis_client_factory), bucket_key='api')
|
|
620
|
+
```
|
|
621
|
+
|
|
622
|
+
Only method calls are proxied: attributes and properties of the connection cannot be reached, since attribute
|
|
623
|
+
access cannot borrow. A sync method whose result stays bound to the connection (a pipeline) is safe only with a
|
|
624
|
+
manager that releases nothing on exit, such as `ConnectionManager`.
|
|
625
|
+
|
|
587
626
|
## Feature Flags
|
|
588
627
|
|
|
589
628
|
`ddutils.feature_flags` is the storage-agnostic part of feature flags: `FeatureFlagRecord` (on or off, the proportion
|
|
@@ -1,22 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Name: ddutils
|
|
3
|
-
Version: 0.4.0
|
|
4
|
-
Summary: Domain Driven Utils Library
|
|
5
|
-
Keywords: python,ddutils
|
|
6
|
-
Author: davyddd
|
|
7
|
-
License-Expression: MIT
|
|
8
|
-
License-File: LICENSE
|
|
9
|
-
Classifier: Programming Language :: Python :: 3
|
|
10
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.14
|
|
14
|
-
Classifier: Typing :: Typed
|
|
15
|
-
Requires-Python: >=3.11, <3.15
|
|
16
|
-
Project-URL: Repository, https://github.com/davyddd/ddutils
|
|
17
|
-
Description-Content-Type: text/markdown
|
|
18
|
-
|
|
19
|
-
# DDUtils
|
|
1
|
+
# ddutils
|
|
20
2
|
|
|
21
3
|
[](https://pypi.python.org/pypi/ddutils)
|
|
22
4
|
[](https://pepy.tech/project/ddutils)
|
|
@@ -24,8 +6,7 @@ Description-Content-Type: text/markdown
|
|
|
24
6
|
[](https://app.codecov.io/github/davyddd/ddutils)
|
|
25
7
|
[](https://github.com/davyddd/ddutils/blob/main/LICENSE)
|
|
26
8
|
|
|
27
|
-
|
|
28
|
-
It focuses on type safety, robustness, and runtime introspection — all without external dependencies.
|
|
9
|
+
Shared utilities of the dd libraries: annotation and class helpers, convertors, scoped registries, connection factories and feature flags
|
|
29
10
|
|
|
30
11
|
## Installation
|
|
31
12
|
|
|
@@ -34,14 +15,9 @@ Install the library using pip:
|
|
|
34
15
|
pip install ddutils
|
|
35
16
|
```
|
|
36
17
|
|
|
37
|
-
## Compatibility
|
|
38
|
-
|
|
39
|
-
Python 3.11 to 3.14, no runtime dependencies. What changed in each release, breaking changes included, is in the
|
|
40
|
-
[GitHub releases](https://github.com/davyddd/ddutils/releases).
|
|
41
|
-
|
|
42
18
|
## Development
|
|
43
19
|
|
|
44
|
-
The project runs entirely in Docker.
|
|
20
|
+
The project runs entirely in Docker. Requires Docker and [Fabric](https://www.fabfile.org/) on the host:
|
|
45
21
|
|
|
46
22
|
```bash
|
|
47
23
|
fab build # build the dev image
|
|
@@ -54,6 +30,15 @@ fab bash # bash inside the container
|
|
|
54
30
|
This project was generated from [dd-lib-stub](https://github.com/davyddd/dd-lib-stub);
|
|
55
31
|
run `uvx copier update` to pull in template updates.
|
|
56
32
|
|
|
33
|
+
## Compatibility
|
|
34
|
+
|
|
35
|
+
Python 3.11 to 3.14. What changed in each release, breaking changes included,
|
|
36
|
+
is in the [GitHub releases](https://github.com/davyddd/ddutils/releases).
|
|
37
|
+
|
|
38
|
+
<!-- The sections below are the library's own; copier update leaves them alone -->
|
|
39
|
+
|
|
40
|
+
No runtime dependencies. The tests need no external services.
|
|
41
|
+
|
|
57
42
|
## Type Annotation Helpers
|
|
58
43
|
|
|
59
44
|
Utilities for inspecting and working with Python type hints and generic types.
|
|
@@ -602,6 +587,24 @@ async with atomic(alias=PostgresDB.REPLICA) as session:
|
|
|
602
587
|
await clickhouse.close()
|
|
603
588
|
```
|
|
604
589
|
|
|
590
|
+
### connection_proxy
|
|
591
|
+
|
|
592
|
+
Some libraries want a connection object at construction and keep it for the life of the process: a rate limiter's
|
|
593
|
+
bucket, a lock implementation. `connection_proxy(factory, *, alias=None)` returns a `ConnectionProxy` typed as the
|
|
594
|
+
connection it stands in for; every method call borrows the connection from the factory for that one call and keeps
|
|
595
|
+
nothing of it, the way a ddsql adapter or a ddredis lock does by hand. A sync method is called inside the borrow as
|
|
596
|
+
well and its result returned as is.
|
|
597
|
+
|
|
598
|
+
```python
|
|
599
|
+
from ddutils.connections import connection_proxy
|
|
600
|
+
|
|
601
|
+
bucket = await RedisBucket.init(rates, redis=connection_proxy(redis_client_factory), bucket_key='api')
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
Only method calls are proxied: attributes and properties of the connection cannot be reached, since attribute
|
|
605
|
+
access cannot borrow. A sync method whose result stays bound to the connection (a pipeline) is safe only with a
|
|
606
|
+
manager that releases nothing on exit, such as `ConnectionManager`.
|
|
607
|
+
|
|
605
608
|
## Feature Flags
|
|
606
609
|
|
|
607
610
|
`ddutils.feature_flags` is the storage-agnostic part of feature flags: `FeatureFlagRecord` (on or off, the proportion
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
from
|
|
1
|
+
import inspect
|
|
2
|
+
from collections.abc import Awaitable, Callable, Hashable, Mapping
|
|
3
|
+
from typing import Any, Generic, TypeVar, cast
|
|
3
4
|
|
|
4
5
|
from ddutils.scoped_registry import ScopedRegistry
|
|
5
6
|
|
|
@@ -78,4 +79,44 @@ class ConnectionManagerFactory(Generic[ConnectionAliasT, ConnectionT, Connection
|
|
|
78
79
|
await registry.clear()
|
|
79
80
|
|
|
80
81
|
|
|
81
|
-
|
|
82
|
+
class ConnectionProxy(Generic[ConnectionT]):
|
|
83
|
+
"""
|
|
84
|
+
Stands in for a connection in front of code that wants to hold one, typically a third-party library that takes a
|
|
85
|
+
client at construction and keeps it for the life of the process (a rate limiter's bucket, a lock implementation).
|
|
86
|
+
Every method call borrows the connection from the factory for that one call and keeps nothing of it, so the
|
|
87
|
+
factory's manager may hand out and release the connection however it sees fit, like `RedisLock` of ddredis does
|
|
88
|
+
by hand. A sync method is called inside the borrow as well and its result returned as is.
|
|
89
|
+
|
|
90
|
+
Only method calls are proxied. An attribute or property of the connection cannot be reached: attribute access is
|
|
91
|
+
synchronous and cannot borrow the connection. A sync method whose result stays bound to the connection (a
|
|
92
|
+
pipeline) is safe only with a manager that releases nothing on exit, such as `ConnectionManager`.
|
|
93
|
+
"""
|
|
94
|
+
|
|
95
|
+
def __init__(self, factory: ConnectionManagerFactory[Any, ConnectionT, Any], *, alias: Hashable | None = None) -> None:
|
|
96
|
+
self._factory = factory
|
|
97
|
+
self._alias = alias
|
|
98
|
+
|
|
99
|
+
def __getattr__(self, name: str) -> Callable[..., Awaitable[Any]]:
|
|
100
|
+
if name.startswith('_'): # private and dunder lookups (copy, pickle, repr) are the proxy's own business
|
|
101
|
+
raise AttributeError(name)
|
|
102
|
+
|
|
103
|
+
async def call(*args: Any, **kwargs: Any) -> Any:
|
|
104
|
+
async with self._factory(alias=self._alias) as connection:
|
|
105
|
+
result = getattr(connection, name)(*args, **kwargs)
|
|
106
|
+
return await result if inspect.isawaitable(result) else result
|
|
107
|
+
|
|
108
|
+
call.__name__ = name
|
|
109
|
+
return call
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def connection_proxy(factory: ConnectionManagerFactory[Any, ConnectionT, Any], *, alias: Hashable | None = None) -> ConnectionT:
|
|
113
|
+
"""
|
|
114
|
+
A `ConnectionProxy` typed as the connection it stands in for, so it can be passed where the connection's type is
|
|
115
|
+
expected without a cast at the call site:
|
|
116
|
+
|
|
117
|
+
bucket = await RedisBucket.init(rates, redis=connection_proxy(redis_client_factory), bucket_key='api')
|
|
118
|
+
"""
|
|
119
|
+
return cast('ConnectionT', ConnectionProxy(factory, alias=alias))
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
__all__ = ('ConnectionManager', 'ConnectionManagerFactory', 'ConnectionProxy', 'connection_proxy')
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "ddutils"
|
|
3
|
-
description = "
|
|
4
|
-
version = "0.4.
|
|
3
|
+
description = "Shared utilities of the dd libraries: annotation and class helpers, convertors, scoped registries, connection factories and feature flags"
|
|
4
|
+
version = "0.4.1"
|
|
5
5
|
license = "MIT"
|
|
6
6
|
license-files = ["LICENSE"]
|
|
7
7
|
readme = "README.md"
|
|
@@ -9,6 +9,23 @@ requires-python = ">=3.11,<3.15"
|
|
|
9
9
|
keywords = [
|
|
10
10
|
"python",
|
|
11
11
|
"ddutils",
|
|
12
|
+
"utils",
|
|
13
|
+
"helpers",
|
|
14
|
+
"type hints",
|
|
15
|
+
"type annotations",
|
|
16
|
+
"introspection",
|
|
17
|
+
"generics",
|
|
18
|
+
"scoped registry",
|
|
19
|
+
"context scope",
|
|
20
|
+
"connection manager",
|
|
21
|
+
"connection factory",
|
|
22
|
+
"feature flags",
|
|
23
|
+
"feature toggle",
|
|
24
|
+
"retry",
|
|
25
|
+
"safe call",
|
|
26
|
+
"decorators",
|
|
27
|
+
"convertors",
|
|
28
|
+
"asyncio",
|
|
12
29
|
]
|
|
13
30
|
classifiers = [
|
|
14
31
|
"Programming Language :: Python :: 3",
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "ddutils"
|
|
3
|
-
description = "
|
|
4
|
-
version = "0.4.
|
|
3
|
+
description = "Shared utilities of the dd libraries: annotation and class helpers, convertors, scoped registries, connection factories and feature flags"
|
|
4
|
+
version = "0.4.1"
|
|
5
5
|
authors = [{ name = "davyddd" }]
|
|
6
6
|
license = "MIT"
|
|
7
7
|
license-files = ["LICENSE"]
|
|
8
8
|
readme = "README.md"
|
|
9
9
|
requires-python = ">=3.11,<3.15"
|
|
10
|
-
keywords = ["python", "ddutils"]
|
|
10
|
+
keywords = ["python", "ddutils", "utils", "helpers", "type hints", "type annotations", "introspection", "generics", "scoped registry", "context scope", "connection manager", "connection factory", "feature flags", "feature toggle", "retry", "safe call", "decorators", "convertors", "asyncio"]
|
|
11
11
|
# uv_build does not derive these from requires-python (poetry did); PyPI and the pyversions badge read them
|
|
12
12
|
classifiers = [
|
|
13
13
|
"Programming Language :: Python :: 3",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|