eric-api 0.0.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.
eric_api-0.0.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Luca Stretti
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,53 @@
1
+ Metadata-Version: 2.3
2
+ Name: eric-api
3
+ Version: 0.0.1
4
+ Summary: A Server side events based messaging microservice implementation
5
+ License: MIT
6
+ Keywords: Server side events,microservice,messaging
7
+ Author: Luca Stretti
8
+ Author-email: laxertu@gmail.com
9
+ Requires-Python: >=3.10,<3.12
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Requires-Dist: dotenv (>=0.9.9,<0.10.0)
15
+ Requires-Dist: eric-sse (>=0.7.1,<0.8.0)
16
+ Requires-Dist: fastapi (>=0.115.12,<0.116.0)
17
+ Requires-Dist: requests (>=2.32.3,<3.0.0)
18
+ Requires-Dist: sse-starlette (>=2.2.1,<3.0.0)
19
+ Requires-Dist: uvicorn (>=0.34.1,<0.35.0)
20
+ Project-URL: Issues, https://github.com/laxertu/eric-api/issues
21
+ Project-URL: Repository, https://github.com/laxertu/eric-api
22
+ Description-Content-Type: text/markdown
23
+
24
+ A ready-to-use SSE messaging microservice implementation.
25
+ Intended for internal use only (all is public here by the moment).
26
+
27
+ Backend relies on https://github.com/laxertu/eric
28
+ REST services rely on FastApi + Uvicorn
29
+
30
+ Features:
31
+ * channel subscription
32
+ * broadcasting
33
+ * message deliver to one client
34
+ * SSE compliant streaming
35
+
36
+ Installation:
37
+
38
+ pip install eric-api
39
+
40
+ Start webserver
41
+
42
+ start-ws
43
+
44
+ Some configuration is allowed by the following environment variables.
45
+ You can set them in a .env file:
46
+
47
+ ERIC_API_HOST
48
+ ERIC_API_PORT
49
+ ERIC_API_LOG_LEVEL
50
+
51
+ See correspondant uvicorn configuration https://www.uvicorn.org/deployment/#running-from-the-command-line for ERIC_API_LOG_LEVEL
52
+
53
+
@@ -0,0 +1,29 @@
1
+ A ready-to-use SSE messaging microservice implementation.
2
+ Intended for internal use only (all is public here by the moment).
3
+
4
+ Backend relies on https://github.com/laxertu/eric
5
+ REST services rely on FastApi + Uvicorn
6
+
7
+ Features:
8
+ * channel subscription
9
+ * broadcasting
10
+ * message deliver to one client
11
+ * SSE compliant streaming
12
+
13
+ Installation:
14
+
15
+ pip install eric-api
16
+
17
+ Start webserver
18
+
19
+ start-ws
20
+
21
+ Some configuration is allowed by the following environment variables.
22
+ You can set them in a .env file:
23
+
24
+ ERIC_API_HOST
25
+ ERIC_API_PORT
26
+ ERIC_API_LOG_LEVEL
27
+
28
+ See correspondant uvicorn configuration https://www.uvicorn.org/deployment/#running-from-the-command-line for ERIC_API_LOG_LEVEL
29
+
@@ -0,0 +1,71 @@
1
+ import os
2
+ import uvicorn
3
+ from logging import getLogger
4
+
5
+ from dotenv import load_dotenv
6
+ from fastapi import FastAPI, Request
7
+ from eric_sse.entities import Message
8
+ from eric_sse.servers import SSEChannelContainer
9
+ from pydantic import BaseModel
10
+ from sse_starlette.sse import EventSourceResponse
11
+
12
+ logger = getLogger(__name__)
13
+ load_dotenv()
14
+
15
+ channel_container = SSEChannelContainer()
16
+
17
+ class MessageDto(BaseModel):
18
+ type: str
19
+ payload: dict | list | str | int | float | None
20
+
21
+ def to_message(self) -> Message:
22
+ return Message(msg_type=self.type, msg_payload=self.payload)
23
+
24
+ app = FastAPI()
25
+
26
+ @app.put("/create")
27
+ async def create():
28
+ channel = channel_container.add()
29
+ return {"channel_id": channel.id}
30
+
31
+
32
+ @app.post("/subscribe")
33
+ async def subscribe(channel_id: str):
34
+ l = channel_container.get(channel_id).add_listener()
35
+ return {"listener_id": l.id}
36
+
37
+ @app.post("/broadcast")
38
+ async def broadcast(channel_id: str, msg: MessageDto):
39
+ channel_container.get(channel_id).broadcast(msg.to_message())
40
+ return None
41
+
42
+ @app.post("/dispatch")
43
+ async def send(channel_id: str, listener_id: str, msg: MessageDto):
44
+ channel_container.get(channel_id).dispatch(listener_id, msg.to_message())
45
+
46
+ @app.get("/stream/{channel_id}/{listener_id}")
47
+ async def stream(request: Request, channel_id: str, listener_id: str):
48
+ channel = channel_container.get(channel_id)
49
+ listener = channel.get_listener(listener_id)
50
+ await listener.start()
51
+ #logger.info(f"wget -q -S -O - 127.0.0.1:8000/stream/{channel_id}/{listener_id} 2>&1")
52
+ if await request.is_disconnected():
53
+ await listener.stop()
54
+ return EventSourceResponse(await channel.message_stream(listener))
55
+
56
+ @app.delete("/listener/{channel_id}/{listener_id}")
57
+ async def delete_listener(channel_id: str, listener_id: str):
58
+ channel_container.get(channel_id).remove_listener(listener_id)
59
+
60
+ @app.delete("/channel/{channel_id}")
61
+ async def delete_channel(channel_id: str):
62
+ channel_container.rm(channel_id)
63
+
64
+
65
+
66
+ def run():
67
+ host = os.getenv("ERIC_API_HOST", "0.0.0.0")
68
+ port = int(os.getenv("ERIC_API_PORT", 8000))
69
+ log_level = os.getenv("ERIC_API_LOG_LEVEL", "info")
70
+
71
+ uvicorn.run(app=app, host=host, port=port, log_level=log_level)
@@ -0,0 +1,36 @@
1
+ [project]
2
+ name = "eric-api"
3
+ version = "0.0.1"
4
+ description = "A Server side events based messaging microservice implementation"
5
+ keywords = ["Server side events", "microservice", "messaging"]
6
+
7
+ authors = [
8
+ {name = "Luca Stretti",email = "laxertu@gmail.com"}
9
+ ]
10
+
11
+
12
+ license = "MIT"
13
+ readme = "README.md"
14
+ requires-python = ">=3.10,<3.12"
15
+ dependencies = [
16
+ "requests (>=2.32.3,<3.0.0)",
17
+ "eric-sse (>=0.7.1,<0.8.0)",
18
+ "fastapi (>=0.115.12,<0.116.0)",
19
+ "sse-starlette (>=2.2.1,<3.0.0)",
20
+ "uvicorn (>=0.34.1,<0.35.0)",
21
+ "dotenv (>=0.9.9,<0.10.0)"
22
+ ]
23
+
24
+ [project.urls]
25
+ Repository = "https://github.com/laxertu/eric-api"
26
+ Issues = "https://github.com/laxertu/eric-api/issues"
27
+
28
+ [build-system]
29
+ requires = ["poetry-core>=2.0.0,<3.0.0"]
30
+ build-backend = "poetry.core.masonry.api"
31
+
32
+ [tool.poetry.scripts]
33
+ start-ws = 'eric_api:run'
34
+
35
+ [tool.setuptools_scm]
36
+