graphserve 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.
Files changed (35) hide show
  1. graphserve-0.1.0/.github/workflows/ci.yml +12 -0
  2. graphserve-0.1.0/.gitignore +10 -0
  3. graphserve-0.1.0/LICENSE +176 -0
  4. graphserve-0.1.0/PKG-INFO +119 -0
  5. graphserve-0.1.0/README.md +86 -0
  6. graphserve-0.1.0/docs/superpowers/plans/2026-06-28-openwebui-compat-tests.md +615 -0
  7. graphserve-0.1.0/pyproject.toml +46 -0
  8. graphserve-0.1.0/src/graphserve/__init__.py +5 -0
  9. graphserve-0.1.0/src/graphserve/_ids.py +51 -0
  10. graphserve-0.1.0/src/graphserve/errors.py +5 -0
  11. graphserve-0.1.0/src/graphserve/py.typed +0 -0
  12. graphserve-0.1.0/src/graphserve/registry.py +43 -0
  13. graphserve-0.1.0/src/graphserve/router.py +58 -0
  14. graphserve-0.1.0/src/graphserve/routes/__init__.py +0 -0
  15. graphserve-0.1.0/src/graphserve/routes/chat.py +156 -0
  16. graphserve-0.1.0/src/graphserve/routes/responses.py +207 -0
  17. graphserve-0.1.0/src/graphserve/translate.py +1055 -0
  18. graphserve-0.1.0/tests/__init__.py +0 -0
  19. graphserve-0.1.0/tests/fakes.py +299 -0
  20. graphserve-0.1.0/tests/test_errors.py +9 -0
  21. graphserve-0.1.0/tests/test_ids.py +38 -0
  22. graphserve-0.1.0/tests/test_openai_sdk_conformance.py +165 -0
  23. graphserve-0.1.0/tests/test_openwebui_compat.py +351 -0
  24. graphserve-0.1.0/tests/test_reasoning.py +278 -0
  25. graphserve-0.1.0/tests/test_registry.py +31 -0
  26. graphserve-0.1.0/tests/test_responses_roundtrip.py +130 -0
  27. graphserve-0.1.0/tests/test_responses_stream.py +197 -0
  28. graphserve-0.1.0/tests/test_router_chat.py +180 -0
  29. graphserve-0.1.0/tests/test_router_responses.py +158 -0
  30. graphserve-0.1.0/tests/test_translate_chat.py +16 -0
  31. graphserve-0.1.0/tests/test_translate_context.py +35 -0
  32. graphserve-0.1.0/tests/test_translate_messages.py +35 -0
  33. graphserve-0.1.0/tests/test_translate_output.py +23 -0
  34. graphserve-0.1.0/tests/test_translate_strict_validation.py +42 -0
  35. graphserve-0.1.0/uv.lock +1311 -0
@@ -0,0 +1,12 @@
1
+ name: ci
2
+ on: [push, pull_request]
3
+ jobs:
4
+ test:
5
+ runs-on: ubuntu-latest
6
+ steps:
7
+ - uses: actions/checkout@v4
8
+ - uses: astral-sh/setup-uv@v5
9
+ - run: uv python install 3.11
10
+ - run: uv sync --extra dev
11
+ - run: uv run ruff check .
12
+ - run: uv run pytest -q
@@ -0,0 +1,10 @@
1
+ .superpowers/
2
+ __pycache__/
3
+ *.py[cod]
4
+ .venv/
5
+ venv/
6
+ dist/
7
+ build/
8
+ *.egg-info/
9
+ .pytest_cache/
10
+ .ruff_cache/
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined in Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
24
+ permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or Object
36
+ form, made available under the License, as indicated by a copyright
37
+ notice that is included in or attached to the work (an example is
38
+ provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original Work and any Derivative Works thereof, and any combinations
50
+ thereof submitted to, or received by, Licensor for inclusion in the Work
51
+ by the copyright owner or by an individual or Legal Entity authorized
52
+ to submit on behalf of the copyright owner. For the purposes of this
53
+ definition, "submitted" means any form of electronic, verbal, or written
54
+ communication sent to the Licensor or its representatives, including but
55
+ not limited to communication on electronic mailing lists, source code
56
+ control systems, and issue tracking systems that are managed by, or on
57
+ behalf of, the Licensor for the purpose of discussing and improving the
58
+ Work, but excluding communication that is conspicuously marked or
59
+ otherwise designated in writing by the copyright owner as "Not a
60
+ Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
63
+ whom a Contribution has been received by Licensor and subsequently
64
+ incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file, then any
107
+ Derivative Works that You distribute must include a readable
108
+ copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE from the Work, provided that
120
+ such additional attribution notices cannot be construed as
121
+ modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions of this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contribution.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,119 @@
1
+ Metadata-Version: 2.4
2
+ Name: graphserve
3
+ Version: 0.1.0
4
+ Summary: Serve any LangGraph graph over the OpenAI Chat Completions + Responses APIs.
5
+ Project-URL: Homepage, https://github.com/AndrewNgo-ini/graphserve
6
+ Project-URL: Repository, https://github.com/AndrewNgo-ini/graphserve
7
+ Project-URL: Issues, https://github.com/AndrewNgo-ini/graphserve/issues
8
+ Author-email: AndrewNgo-ini <46411807+AndrewNgo-ini@users.noreply.github.com>
9
+ License-Expression: Apache-2.0
10
+ License-File: LICENSE
11
+ Keywords: agents,chat-completions,fastapi,langgraph,llm,openai,responses-api,sse
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Framework :: FastAPI
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Requires-Python: >=3.11
22
+ Requires-Dist: fastapi>=0.137.0
23
+ Requires-Dist: langchain-core>=1.4.0
24
+ Requires-Dist: langgraph>=1.2.0
25
+ Requires-Dist: openai>=2.41.0
26
+ Requires-Dist: pydantic>=2.13.0
27
+ Provides-Extra: dev
28
+ Requires-Dist: httpx>=0.28; extra == 'dev'
29
+ Requires-Dist: pytest-asyncio>=0.25; extra == 'dev'
30
+ Requires-Dist: pytest>=8.0; extra == 'dev'
31
+ Requires-Dist: ruff>=0.6; extra == 'dev'
32
+ Description-Content-Type: text/markdown
33
+
34
+ # GraphServe
35
+
36
+ GraphServe is an open-source Python library that serves any LangGraph graph over the OpenAI Chat Completions and Responses APIs, enabling seamless integration of agent workflows into OpenAI-compatible applications.
37
+
38
+ ## Installation
39
+
40
+ ```bash
41
+ pip install graphserve
42
+ ```
43
+
44
+ ## Quickstart
45
+
46
+ ```python
47
+ from fastapi import FastAPI
48
+ from langgraph.graph import StateGraph, START, END
49
+ from graphserve import GraphRegistry, GraphConfig, create_openai_router
50
+
51
+ # 1. Build your LangGraph graph
52
+ graph = StateGraph(...)
53
+ # ... add nodes and edges ...
54
+ compiled = graph.compile()
55
+
56
+ # 2. Register it under a model name
57
+ registry = GraphRegistry()
58
+ registry.register("my-agent", GraphConfig(graph=compiled))
59
+
60
+ # 3. Mount the OpenAI-compatible router on your FastAPI app
61
+ app = FastAPI()
62
+ app.include_router(create_openai_router(registry), prefix="/v1")
63
+ ```
64
+
65
+ Your app now exposes:
66
+
67
+ | Route | Description |
68
+ |---|---|
69
+ | `GET /v1/models` | List registered graphs |
70
+ | `POST /v1/responses` | Create a response (streaming or non-streaming) |
71
+ | `GET /v1/responses/{id}` | Retrieve a previous response |
72
+ | `DELETE /v1/responses/{id}` | Delete a response |
73
+ | `POST /v1/chat/completions` | Chat Completions API |
74
+
75
+ ## Public API
76
+
77
+ | Export | Description |
78
+ |---|---|
79
+ | `GraphRegistry` | Registry mapping model names to graph configs |
80
+ | `GraphConfig` | Holds a single already-compiled `graph` to serve (graph-only) |
81
+ | `create_openai_router` | Builds a FastAPI `APIRouter` with all OpenAI-compatible routes |
82
+ | `ConversationStore` | Protocol for plugging in a custom conversation metadata backend |
83
+
84
+ ## `create_openai_router` options
85
+
86
+ ```python
87
+ create_openai_router(
88
+ registry, # GraphRegistry — required
89
+ store=None, # ConversationStore — defaults to InMemoryConversationStore
90
+ )
91
+ ```
92
+
93
+ GraphServe is a pure bind layer. Cross-cutting concerns are the consumer's job,
94
+ applied with standard tools:
95
+
96
+ - **Auth** — apply it where you mount the router:
97
+ ```python
98
+ app.include_router(create_openai_router(registry), prefix="/v1",
99
+ dependencies=[Depends(verify_api_key)])
100
+ ```
101
+ - **Callbacks / tracing** — attach to your graph when you build it.
102
+
103
+ Per-request runtime context is derived generically from the OpenAI request and
104
+ exposed to the graph as LangGraph runtime `context`: `user` → `context["user_id"]`,
105
+ `instructions` → `context["metadata"]["custom_instructions"]`, and `metadata` is
106
+ passed through as `context["metadata"]`. Graphs read what they need and ignore the rest.
107
+
108
+ > **Stateful GET / `previous_response_id` continuity** requires the registered
109
+ > graph to be compiled with a LangGraph checkpointer — this is the consumer's
110
+ > responsibility (e.g. `graph.compile(checkpointer=MemorySaver())`).
111
+ > GraphServe reads thread state via `graph.aget_state(...)` at GET time.
112
+
113
+ ## Streaming
114
+
115
+ Pass `"stream": true` in the request body to receive Server-Sent Events following the OpenAI Responses API event schema (`response.created`, `response.output_item.added`, `response.output_text.delta`, `response.completed`, etc.).
116
+
117
+ ## License
118
+
119
+ MIT
@@ -0,0 +1,86 @@
1
+ # GraphServe
2
+
3
+ GraphServe is an open-source Python library that serves any LangGraph graph over the OpenAI Chat Completions and Responses APIs, enabling seamless integration of agent workflows into OpenAI-compatible applications.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install graphserve
9
+ ```
10
+
11
+ ## Quickstart
12
+
13
+ ```python
14
+ from fastapi import FastAPI
15
+ from langgraph.graph import StateGraph, START, END
16
+ from graphserve import GraphRegistry, GraphConfig, create_openai_router
17
+
18
+ # 1. Build your LangGraph graph
19
+ graph = StateGraph(...)
20
+ # ... add nodes and edges ...
21
+ compiled = graph.compile()
22
+
23
+ # 2. Register it under a model name
24
+ registry = GraphRegistry()
25
+ registry.register("my-agent", GraphConfig(graph=compiled))
26
+
27
+ # 3. Mount the OpenAI-compatible router on your FastAPI app
28
+ app = FastAPI()
29
+ app.include_router(create_openai_router(registry), prefix="/v1")
30
+ ```
31
+
32
+ Your app now exposes:
33
+
34
+ | Route | Description |
35
+ |---|---|
36
+ | `GET /v1/models` | List registered graphs |
37
+ | `POST /v1/responses` | Create a response (streaming or non-streaming) |
38
+ | `GET /v1/responses/{id}` | Retrieve a previous response |
39
+ | `DELETE /v1/responses/{id}` | Delete a response |
40
+ | `POST /v1/chat/completions` | Chat Completions API |
41
+
42
+ ## Public API
43
+
44
+ | Export | Description |
45
+ |---|---|
46
+ | `GraphRegistry` | Registry mapping model names to graph configs |
47
+ | `GraphConfig` | Holds a single already-compiled `graph` to serve (graph-only) |
48
+ | `create_openai_router` | Builds a FastAPI `APIRouter` with all OpenAI-compatible routes |
49
+ | `ConversationStore` | Protocol for plugging in a custom conversation metadata backend |
50
+
51
+ ## `create_openai_router` options
52
+
53
+ ```python
54
+ create_openai_router(
55
+ registry, # GraphRegistry — required
56
+ store=None, # ConversationStore — defaults to InMemoryConversationStore
57
+ )
58
+ ```
59
+
60
+ GraphServe is a pure bind layer. Cross-cutting concerns are the consumer's job,
61
+ applied with standard tools:
62
+
63
+ - **Auth** — apply it where you mount the router:
64
+ ```python
65
+ app.include_router(create_openai_router(registry), prefix="/v1",
66
+ dependencies=[Depends(verify_api_key)])
67
+ ```
68
+ - **Callbacks / tracing** — attach to your graph when you build it.
69
+
70
+ Per-request runtime context is derived generically from the OpenAI request and
71
+ exposed to the graph as LangGraph runtime `context`: `user` → `context["user_id"]`,
72
+ `instructions` → `context["metadata"]["custom_instructions"]`, and `metadata` is
73
+ passed through as `context["metadata"]`. Graphs read what they need and ignore the rest.
74
+
75
+ > **Stateful GET / `previous_response_id` continuity** requires the registered
76
+ > graph to be compiled with a LangGraph checkpointer — this is the consumer's
77
+ > responsibility (e.g. `graph.compile(checkpointer=MemorySaver())`).
78
+ > GraphServe reads thread state via `graph.aget_state(...)` at GET time.
79
+
80
+ ## Streaming
81
+
82
+ Pass `"stream": true` in the request body to receive Server-Sent Events following the OpenAI Responses API event schema (`response.created`, `response.output_item.added`, `response.output_text.delta`, `response.completed`, etc.).
83
+
84
+ ## License
85
+
86
+ MIT