ddutils 0.4.0__tar.gz → 0.4.2__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.
@@ -1,4 +1,23 @@
1
- # DDUtils
1
+ Metadata-Version: 2.4
2
+ Name: ddutils
3
+ Version: 0.4.2
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: Programming Language :: Python :: 3.15
15
+ Classifier: Typing :: Typed
16
+ Requires-Python: >=3.11, <3.16
17
+ Project-URL: Repository, https://github.com/davyddd/ddutils
18
+ Description-Content-Type: text/markdown
19
+
20
+ # ddutils
2
21
 
3
22
  [![pypi](https://img.shields.io/pypi/v/ddutils.svg)](https://pypi.python.org/pypi/ddutils)
4
23
  [![downloads](https://static.pepy.tech/badge/ddutils/month)](https://pepy.tech/project/ddutils)
@@ -6,8 +25,7 @@
6
25
  [![codecov](https://codecov.io/gh/davyddd/ddutils/branch/main/graph/badge.svg)](https://app.codecov.io/github/davyddd/ddutils)
7
26
  [![license](https://img.shields.io/github/license/davyddd/ddutils.svg)](https://github.com/davyddd/ddutils/blob/main/LICENSE)
8
27
 
9
- **DDUtils** is a lightweight Python library that provides helper functions and decorators for common programming tasks.
10
- It focuses on type safety, robustness, and runtime introspection — all without external dependencies.
28
+ Shared utilities of the dd libraries: annotation and class helpers, convertors, scoped registries, connection factories and feature flags
11
29
 
12
30
  ## Installation
13
31
 
@@ -16,14 +34,9 @@ Install the library using pip:
16
34
  pip install ddutils
17
35
  ```
18
36
 
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
37
  ## Development
25
38
 
26
- The project runs entirely in Docker. The tests need no external services. Requires Docker and [Fabric](https://www.fabfile.org/) on the host:
39
+ The project runs entirely in Docker. Requires Docker and [Fabric](https://www.fabfile.org/) on the host:
27
40
 
28
41
  ```bash
29
42
  fab build # build the dev image
@@ -36,6 +49,15 @@ fab bash # bash inside the container
36
49
  This project was generated from [dd-lib-stub](https://github.com/davyddd/dd-lib-stub);
37
50
  run `uvx copier update` to pull in template updates.
38
51
 
52
+ ## Compatibility
53
+
54
+ Python 3.11 to 3.15. What changed in each release, breaking changes included,
55
+ is in the [GitHub releases](https://github.com/davyddd/ddutils/releases).
56
+
57
+ <!-- The sections below are the library's own; copier update leaves them alone -->
58
+
59
+ No runtime dependencies. The tests need no external services.
60
+
39
61
  ## Type Annotation Helpers
40
62
 
41
63
  Utilities for inspecting and working with Python type hints and generic types.
@@ -584,6 +606,24 @@ async with atomic(alias=PostgresDB.REPLICA) as session:
584
606
  await clickhouse.close()
585
607
  ```
586
608
 
609
+ ### connection_proxy
610
+
611
+ Some libraries want a connection object at construction and keep it for the life of the process: a rate limiter's
612
+ bucket, a lock implementation. `connection_proxy(factory, *, alias=None)` returns a `ConnectionProxy` typed as the
613
+ connection it stands in for; every method call borrows the connection from the factory for that one call and keeps
614
+ nothing of it, the way a ddsql adapter or a ddredis lock does by hand. A sync method is called inside the borrow as
615
+ well and its result returned as is.
616
+
617
+ ```python
618
+ from ddutils.connections import connection_proxy
619
+
620
+ bucket = await RedisBucket.init(rates, redis=connection_proxy(redis_client_factory), bucket_key='api')
621
+ ```
622
+
623
+ Only method calls are proxied: attributes and properties of the connection cannot be reached, since attribute
624
+ access cannot borrow. A sync method whose result stays bound to the connection (a pipeline) is safe only with a
625
+ manager that releases nothing on exit, such as `ConnectionManager`.
626
+
587
627
  ## Feature Flags
588
628
 
589
629
  `ddutils.feature_flags` is the storage-agnostic part of feature flags: `FeatureFlagRecord` (on or off, the proportion
@@ -1,22 +1,4 @@
1
- Metadata-Version: 2.4
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
  [![pypi](https://img.shields.io/pypi/v/ddutils.svg)](https://pypi.python.org/pypi/ddutils)
22
4
  [![downloads](https://static.pepy.tech/badge/ddutils/month)](https://pepy.tech/project/ddutils)
@@ -24,8 +6,7 @@ Description-Content-Type: text/markdown
24
6
  [![codecov](https://codecov.io/gh/davyddd/ddutils/branch/main/graph/badge.svg)](https://app.codecov.io/github/davyddd/ddutils)
25
7
  [![license](https://img.shields.io/github/license/davyddd/ddutils.svg)](https://github.com/davyddd/ddutils/blob/main/LICENSE)
26
8
 
27
- **DDUtils** is a lightweight Python library that provides helper functions and decorators for common programming tasks.
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. The tests need no external services. Requires Docker and [Fabric](https://www.fabfile.org/) on the host:
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.15. 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
- from collections.abc import Callable, Hashable, Mapping
2
- from typing import Any, Generic, TypeVar
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
- __all__ = ('ConnectionManager', 'ConnectionManagerFactory')
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,14 +1,31 @@
1
1
  [project]
2
2
  name = "ddutils"
3
- description = "Domain Driven Utils Library"
4
- version = "0.4.0"
3
+ description = "Shared utilities of the dd libraries: annotation and class helpers, convertors, scoped registries, connection factories and feature flags"
4
+ version = "0.4.2"
5
5
  license = "MIT"
6
6
  license-files = ["LICENSE"]
7
7
  readme = "README.md"
8
- requires-python = ">=3.11,<3.15"
8
+ requires-python = ">=3.11,<3.16"
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",
@@ -16,6 +33,7 @@ classifiers = [
16
33
  "Programming Language :: Python :: 3.12",
17
34
  "Programming Language :: Python :: 3.13",
18
35
  "Programming Language :: Python :: 3.14",
36
+ "Programming Language :: Python :: 3.15",
19
37
  "Typing :: Typed",
20
38
  ]
21
39
  dependencies = []
@@ -46,5 +64,5 @@ linter = [
46
64
  module-root = ""
47
65
 
48
66
  [build-system]
49
- requires = ["uv_build>=0.12.0,<0.13.0"]
67
+ requires = ["uv_build>=0.13.0,<0.14.0"]
50
68
  build-backend = "uv_build"
@@ -1,13 +1,13 @@
1
1
  [project]
2
2
  name = "ddutils"
3
- description = "Domain Driven Utils Library"
4
- version = "0.4.0"
3
+ description = "Shared utilities of the dd libraries: annotation and class helpers, convertors, scoped registries, connection factories and feature flags"
4
+ version = "0.4.2"
5
5
  authors = [{ name = "davyddd" }]
6
6
  license = "MIT"
7
7
  license-files = ["LICENSE"]
8
8
  readme = "README.md"
9
- requires-python = ">=3.11,<3.15"
10
- keywords = ["python", "ddutils"]
9
+ requires-python = ">=3.11,<3.16"
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",
@@ -15,6 +15,7 @@ classifiers = [
15
15
  "Programming Language :: Python :: 3.12",
16
16
  "Programming Language :: Python :: 3.13",
17
17
  "Programming Language :: Python :: 3.14",
18
+ "Programming Language :: Python :: 3.15",
18
19
  "Typing :: Typed",
19
20
  ]
20
21
  dependencies = []
@@ -42,5 +43,5 @@ linter = [
42
43
  module-root = ""
43
44
 
44
45
  [build-system]
45
- requires = ["uv_build>=0.12.0,<0.13.0"]
46
+ requires = ["uv_build>=0.13.0,<0.14.0"]
46
47
  build-backend = "uv_build"
File without changes
File without changes
File without changes
File without changes