aspyx-service 0.9.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.

Potentially problematic release.


This version of aspyx-service might be problematic. Click here for more details.

@@ -0,0 +1,194 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
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
+
110
+ # pdm
111
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112
+ #pdm.lock
113
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114
+ # in version control.
115
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
116
+ .pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
121
+ __pypackages__/
122
+
123
+ # Celery stuff
124
+ celerybeat-schedule
125
+ celerybeat.pid
126
+
127
+ # SageMath parsed files
128
+ *.sage.py
129
+
130
+ # Environments
131
+ .env
132
+ .venv
133
+ env/
134
+ venv/
135
+ ENV/
136
+ env.bak/
137
+ venv.bak/
138
+
139
+ # Spyder project settings
140
+ .spyderproject
141
+ .spyproject
142
+
143
+ # Rope project settings
144
+ .ropeproject
145
+
146
+ # mkdocs documentation
147
+ /site
148
+
149
+ # mypy
150
+ .mypy_cache/
151
+ .dmypy.json
152
+ dmypy.json
153
+
154
+ # Pyre type checker
155
+ .pyre/
156
+
157
+ # pytype static type analyzer
158
+ .pytype/
159
+
160
+ # Cython debug symbols
161
+ cython_debug/
162
+
163
+ # PyCharm
164
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
165
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
166
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
167
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
168
+ #.idea/
169
+
170
+ # Abstra
171
+ # Abstra is an AI-powered process automation framework.
172
+ # Ignore directories containing user credentials, local state, and settings.
173
+ # Learn more at https://abstra.io/docs
174
+ .abstra/
175
+
176
+ # Visual Studio Code
177
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
178
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
179
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
180
+ # you could uncomment the following to ignore the enitre vscode folder
181
+ # .vscode/
182
+
183
+ # Ruff stuff:
184
+ .ruff_cache/
185
+
186
+ # PyPI configuration file
187
+ .pypirc
188
+
189
+ # Cursor
190
+ # Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
191
+ # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
192
+ # refer to https://docs.cursor.com/context/ignore-files
193
+ .cursorignore
194
+ .cursorindexingignore
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Andreas Ernst
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.
@@ -0,0 +1,36 @@
1
+ Metadata-Version: 2.4
2
+ Name: aspyx_service
3
+ Version: 0.9.0
4
+ Summary: Service framework on top of aspyx
5
+ Author-email: Andreas Ernst <andreas.ernst7@gmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2025 Andreas Ernst
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+ License-File: LICENSE
28
+ Requires-Python: >=3.9
29
+ Requires-Dist: aspyx>=1.4.1
30
+ Requires-Dist: fastapi~=0.115.13
31
+ Requires-Dist: httpx~=0.28.1
32
+ Requires-Dist: msgpack~=1.1.1
33
+ Requires-Dist: python-consul2~=0.1.5
34
+ Description-Content-Type: text/markdown
35
+
36
+ aspyx-service
@@ -0,0 +1 @@
1
+ aspyx-service
@@ -0,0 +1,32 @@
1
+
2
+
3
+ [project]
4
+ name = "aspyx_service"
5
+ version = "0.9.0"
6
+ description = "Service framework on top of aspyx"
7
+ authors = [{ name = "Andreas Ernst", email = "andreas.ernst7@gmail.com" }]
8
+ readme = "README.md"
9
+ license = { file = "LICENSE" }
10
+ requires-python = ">=3.9"
11
+ dependencies = [
12
+ "aspyx>=1.4.1",
13
+ "python-consul2~=0.1.5",
14
+ "fastapi~=0.115.13",
15
+ "httpx~=0.28.1",
16
+ "msgpack~=1.1.1"
17
+ ]
18
+
19
+ #"aspyx @ file://../aspyx", # Local editable ref
20
+
21
+ [build-system]
22
+ requires = ["hatchling"]
23
+ build-backend = "hatchling.build"
24
+
25
+ [tool.hatch.build]
26
+ source = "src"
27
+
28
+ [tool.hatch.build.targets.wheel]
29
+ packages = ["src/aspyx_service"]
30
+
31
+ [tool.hatch.metadata]
32
+ allow-direct-references = true
@@ -0,0 +1,71 @@
1
+ """
2
+ This module provides the core Aspyx service management framework allowing for service discovery and transparent remoting including multiple possible transport protocols.
3
+ """
4
+
5
+ from aspyx.di import module
6
+
7
+ from .service import ServiceException, Server, Channel, ComponentDescriptor, inject_service, ChannelAddress, ServiceAddress, ServiceManager, Component, Service, AbstractComponent, ComponentStatus, ComponentRegistry, implementation, health, component, service
8
+ from .channels import HTTPXChannel, DispatchJSONChannel
9
+ from .registries import ConsulComponentRegistry
10
+ from .server import FastAPIServer
11
+ from .healthcheck import health_checks, health_check, HealthCheckManager, HealthStatus
12
+ from .restchannel import RestChannel, post, get, put, delete, QueryParam, Body, rest
13
+
14
+
15
+ @module()
16
+ class ServiceModule:
17
+ def __init__(self):
18
+ pass
19
+
20
+ __all__ = [
21
+ # service
22
+
23
+ "ServiceManager",
24
+ "ServiceModule",
25
+ "ServiceException",
26
+ "Server",
27
+ "Component",
28
+ "Service",
29
+ "Channel",
30
+ "AbstractComponent",
31
+ "ComponentStatus",
32
+ "ComponentDescriptor",
33
+ "ComponentRegistry",
34
+ "ChannelAddress",
35
+ "ServiceAddress",
36
+ "health",
37
+ "component",
38
+ "service",
39
+ "implementation",
40
+ "inject_service",
41
+
42
+ # healthcheck
43
+
44
+ # serialization
45
+
46
+ # "deserialize",
47
+
48
+ # channel
49
+
50
+ "HTTPXChannel",
51
+ "DispatchJSONChannel",
52
+
53
+ # rest
54
+
55
+ "RestChannel",
56
+ "post",
57
+ "get",
58
+ "put",
59
+ "delete",
60
+ "rest",
61
+ "QueryParam",
62
+ "Body",
63
+
64
+ # registries
65
+
66
+ "ConsulComponentRegistry",
67
+
68
+ # server
69
+
70
+ "FastAPIServer"
71
+ ]
@@ -0,0 +1,210 @@
1
+ """
2
+ Service management and dependency injection framework.
3
+ """
4
+ from __future__ import annotations
5
+
6
+ from typing import Type, Optional, Any, Callable
7
+
8
+ import msgpack
9
+ from httpx import Client, AsyncClient
10
+ from pydantic import BaseModel
11
+
12
+ from aspyx.reflection import DynamicProxy, TypeDescriptor
13
+ from .service import ServiceManager
14
+
15
+ from .service import ComponentDescriptor, ServiceAddress, ServiceException, channel, Channel, RemoteServiceException
16
+ from .serialization import get_deserializer
17
+
18
+
19
+ class HTTPXChannel(Channel):
20
+ __slots__ = [
21
+ "client",
22
+ "async_client",
23
+ "service_names",
24
+ "deserializers"
25
+ ]
26
+
27
+ # constructor
28
+
29
+ def __init__(self, name):
30
+ super().__init__(name)
31
+
32
+ self.client: Optional[Client] = None
33
+ self.async_client: Optional[AsyncClient] = None
34
+ self.service_names: dict[Type, str] = {}
35
+ self.deserializers: dict[Callable, Callable] = {}
36
+
37
+ # protected
38
+
39
+ def get_deserializer(self, type: Type, method: Callable) -> Type:
40
+ deserializer = self.deserializers.get(method, None)
41
+ if deserializer is None:
42
+ return_type = TypeDescriptor.for_type(type).get_method(method.__name__).return_type
43
+
44
+ deserializer = get_deserializer(return_type)
45
+
46
+ self.deserializers[method] = deserializer
47
+
48
+ return deserializer
49
+
50
+ # override
51
+
52
+ def setup(self, component_descriptor: ComponentDescriptor, address: ServiceAddress):
53
+ super().setup(component_descriptor, address)
54
+
55
+ # remember service names
56
+
57
+ for service in component_descriptor.services:
58
+ self.service_names[service.type] = service.name
59
+
60
+ # make client
61
+
62
+ self.client = self.make_client()
63
+ self.async_client = self.make_async_client()
64
+
65
+ # public
66
+
67
+ def get_client(self) -> Client:
68
+ if self.client is None:
69
+ self.client = self.make_client()
70
+
71
+ return self.client
72
+
73
+ def get_async_client(self) -> Client:
74
+ if self.async_client is None:
75
+ self.async_client = self.make_async_client()
76
+
77
+ return self.async_client
78
+
79
+ def make_client(self):
80
+ return Client() # base_url=url
81
+
82
+ def make_async_client(self):
83
+ return AsyncClient() # base_url=url
84
+
85
+ class Request(BaseModel):
86
+ method: str # component:service:method
87
+ args: tuple[Any, ...]
88
+
89
+ class Response(BaseModel):
90
+ result: Optional[Any]
91
+ exception: Optional[Any]
92
+
93
+ @channel("dispatch-json")
94
+ class DispatchJSONChannel(HTTPXChannel):
95
+ # constructor
96
+
97
+ def __init__(self):
98
+ super().__init__("dispatch-json")
99
+
100
+ # internal
101
+
102
+ # implement Channel
103
+
104
+ def set_address(self, address: Optional[ServiceAddress]):
105
+ ServiceManager.logger.info("channel %s got an address %s", self.name, address)
106
+
107
+ super().set_address(address)
108
+
109
+ def setup(self, component_descriptor: ComponentDescriptor, address: ServiceAddress):
110
+ super().setup(component_descriptor, address)
111
+
112
+ def invoke(self, invocation: DynamicProxy.Invocation):
113
+ service_name = self.service_names[invocation.type] # map type to registered service name
114
+ request = Request(method=f"{self.component_descriptor.name}:{service_name}:{invocation.method.__name__}", args=invocation.args)
115
+
116
+ try:
117
+ if self.client is not None:
118
+ result = Response(**self.get_client().post(f"{self.get_url()}/invoke", json=request.dict(), timeout=30000.0).json())
119
+ if result.exception is not None:
120
+ raise RemoteServiceException(f"server side exception {result.exception}")
121
+
122
+ return self.get_deserializer(invocation.type, invocation.method)(result.result)
123
+ else:
124
+ raise ServiceException(f"no url for channel {self.name} for component {self.component_descriptor.name} registered")
125
+ except Exception as e:
126
+ raise ServiceException(f"communication exception {e}") from e
127
+
128
+ async def invoke_async(self, invocation: DynamicProxy.Invocation):
129
+ service_name = self.service_names[invocation.type] # map type to registered service name
130
+ request = Request(method=f"{self.component_descriptor.name}:{service_name}:{invocation.method.__name__}",
131
+ args=invocation.args)
132
+
133
+ try:
134
+ if self.async_client is not None:
135
+ data = await self.async_client.post(f"{self.get_url()}/invoke", json=request.dict(), timeout=30000.0)
136
+ result = Response(**data.json())
137
+ if result.exception is not None:
138
+ raise RemoteServiceException(f"server side exception {result.exception}")
139
+
140
+ return self.get_deserializer(invocation.type, invocation.method)(result.result)
141
+ else:
142
+ raise ServiceException(
143
+ f"no url for channel {self.name} for component {self.component_descriptor.name} registered")
144
+ except Exception as e:
145
+ raise ServiceException(f"communication exception {e}") from e
146
+
147
+ @channel("dispatch-msgpack")
148
+ class DispatchMSPackChannel(HTTPXChannel):
149
+ # constructor
150
+
151
+ def __init__(self):
152
+ super().__init__("dispatch-msgpack")
153
+
154
+ # override
155
+
156
+ def set_address(self, address: Optional[ServiceAddress]):
157
+ ServiceManager.logger.info("channel %s got an address %s", self.name, address)
158
+
159
+ super().set_address(address)
160
+
161
+ def invoke(self, invocation: DynamicProxy.Invocation):
162
+ service_name = self.service_names[invocation.type] # map type to registered service name
163
+ request = Request(method=f"{self.component_descriptor.name}:{service_name}:{invocation.method.__name__}",
164
+ args=invocation.args)
165
+
166
+ try:
167
+ packed = msgpack.packb(request.dict(), use_bin_type=True)
168
+
169
+ response = self.get_client().post(
170
+ f"{self.get_url()}/invoke",
171
+ content=packed,
172
+ headers={"Content-Type": "application/msgpack"},
173
+ timeout=30.0
174
+ )
175
+
176
+ result = msgpack.unpackb(response.content, raw=False)
177
+
178
+ if result.get("exception", None):
179
+ raise RemoteServiceException(f"server-side: {result['exception']}")
180
+
181
+ return self.get_deserializer(invocation.type, invocation.method)(result["result"])
182
+
183
+ except Exception as e:
184
+ raise ServiceException(f"msgpack exception: {e}") from e
185
+
186
+ async def invoke_async(self, invocation: DynamicProxy.Invocation):
187
+ service_name = self.service_names[invocation.type] # map type to registered service name
188
+ request = Request(method=f"{self.component_descriptor.name}:{service_name}:{invocation.method.__name__}",
189
+ args=invocation.args)
190
+
191
+ try:
192
+ packed = msgpack.packb(request.dict(), use_bin_type=True)
193
+
194
+ response = await self.get_async_client().post(
195
+ f"{self.get_url()}/invoke",
196
+ content=packed,
197
+ headers={"Content-Type": "application/msgpack"},
198
+ timeout=30.0
199
+ )
200
+
201
+ result = msgpack.unpackb(response.content, raw=False)
202
+
203
+ if result.get("exception", None):
204
+ raise RemoteServiceException(f"server-side: {result['exception']}")
205
+
206
+ return self.get_deserializer(invocation.type, invocation.method)(result["result"])
207
+
208
+ except Exception as e:
209
+ raise ServiceException(f"msgpack exception: {e}") from e
210
+