morphik 0.2.0__py3-none-any.whl → 0.2.1__py3-none-any.whl
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.
morphik/__init__.py
CHANGED
morphik/async_.py
CHANGED
@@ -3,6 +3,7 @@ import logging
|
|
3
3
|
from io import BytesIO, IOBase
|
4
4
|
from pathlib import Path
|
5
5
|
from typing import Any, BinaryIO, Dict, List, Optional, Type, Union
|
6
|
+
from datetime import datetime
|
6
7
|
|
7
8
|
import httpx
|
8
9
|
from pydantic import BaseModel
|
@@ -2590,3 +2591,77 @@ class AsyncMorphik:
|
|
2590
2591
|
raise RuntimeError(graph.error or "Graph processing failed")
|
2591
2592
|
await asyncio.sleep(check_interval_seconds)
|
2592
2593
|
raise TimeoutError("Timed out waiting for graph completion")
|
2594
|
+
|
2595
|
+
async def ping(self) -> Dict[str, Any]:
|
2596
|
+
"""Simple health-check call to ``/ping`` endpoint."""
|
2597
|
+
return await self._request("GET", "ping")
|
2598
|
+
|
2599
|
+
# ------------------------------------------------------------------
|
2600
|
+
# Chat API ----------------------------------------------------------
|
2601
|
+
# ------------------------------------------------------------------
|
2602
|
+
async def get_chat_history(self, chat_id: str) -> List[Dict[str, Any]]:
|
2603
|
+
"""Return the full message history for *chat_id*."""
|
2604
|
+
return await self._request("GET", f"chat/{chat_id}")
|
2605
|
+
|
2606
|
+
async def list_chat_conversations(self, limit: int = 100) -> List[Dict[str, Any]]:
|
2607
|
+
"""List recent chat conversations for the current user (async)."""
|
2608
|
+
limit_capped = max(1, min(limit, 500))
|
2609
|
+
return await self._request("GET", "chats", params={"limit": limit_capped})
|
2610
|
+
|
2611
|
+
# ------------------------------------------------------------------
|
2612
|
+
# Usage API ---------------------------------------------------------
|
2613
|
+
# ------------------------------------------------------------------
|
2614
|
+
async def get_usage_stats(self) -> Dict[str, int]:
|
2615
|
+
"""Return cumulative token usage statistics (async)."""
|
2616
|
+
return await self._request("GET", "usage/stats")
|
2617
|
+
|
2618
|
+
async def get_recent_usage(
|
2619
|
+
self,
|
2620
|
+
operation_type: Optional[str] = None,
|
2621
|
+
since: Optional["datetime"] = None,
|
2622
|
+
status: Optional[str] = None,
|
2623
|
+
) -> List[Dict[str, Any]]:
|
2624
|
+
"""Return recent usage entries with optional filtering (async)."""
|
2625
|
+
from datetime import datetime
|
2626
|
+
|
2627
|
+
params: Dict[str, Any] = {}
|
2628
|
+
if operation_type:
|
2629
|
+
params["operation_type"] = operation_type
|
2630
|
+
if since:
|
2631
|
+
params["since"] = since.isoformat() if isinstance(since, datetime) else str(since)
|
2632
|
+
if status:
|
2633
|
+
params["status"] = status
|
2634
|
+
return await self._request("GET", "usage/recent", params=params)
|
2635
|
+
|
2636
|
+
# ------------------------------------------------------------------
|
2637
|
+
# Graph helpers -----------------------------------------------------
|
2638
|
+
# ------------------------------------------------------------------
|
2639
|
+
async def get_graph_visualization(
|
2640
|
+
self,
|
2641
|
+
name: str,
|
2642
|
+
folder_name: Optional[Union[str, List[str]]] = None,
|
2643
|
+
end_user_id: Optional[str] = None,
|
2644
|
+
) -> Dict[str, Any]:
|
2645
|
+
"""Fetch nodes & links for visualising *name* graph (async)."""
|
2646
|
+
params: Dict[str, Any] = {}
|
2647
|
+
if folder_name is not None:
|
2648
|
+
params["folder_name"] = folder_name
|
2649
|
+
if end_user_id is not None:
|
2650
|
+
params["end_user_id"] = end_user_id
|
2651
|
+
return await self._request("GET", f"graph/{name}/visualization", params=params)
|
2652
|
+
|
2653
|
+
async def check_workflow_status(
|
2654
|
+
self, workflow_id: str, run_id: Optional[str] = None
|
2655
|
+
) -> Dict[str, Any]:
|
2656
|
+
"""Poll the status of an async graph build/update workflow."""
|
2657
|
+
params = {"run_id": run_id} if run_id else None
|
2658
|
+
return await self._request("GET", f"graph/workflow/{workflow_id}/status", params=params)
|
2659
|
+
|
2660
|
+
# ------------------------------------------------------------------
|
2661
|
+
# Document download helpers ----------------------------------------
|
2662
|
+
# ------------------------------------------------------------------
|
2663
|
+
async def get_document_download_url(self, document_id: str, expires_in: int = 3600) -> Dict[str, Any]:
|
2664
|
+
"""Generate a presigned download URL for a document (async)."""
|
2665
|
+
return await self._request(
|
2666
|
+
"GET", f"documents/{document_id}/download_url", params={"expires_in": expires_in}
|
2667
|
+
)
|
morphik/sync.py
CHANGED
@@ -3,6 +3,7 @@ import logging
|
|
3
3
|
from io import BytesIO, IOBase
|
4
4
|
from pathlib import Path
|
5
5
|
from typing import Any, BinaryIO, Dict, List, Optional, Type, Union
|
6
|
+
from datetime import datetime
|
6
7
|
|
7
8
|
import httpx
|
8
9
|
from pydantic import BaseModel
|
@@ -2763,3 +2764,96 @@ class Morphik:
|
|
2763
2764
|
raise RuntimeError(graph.error or "Graph processing failed")
|
2764
2765
|
time.sleep(check_interval_seconds)
|
2765
2766
|
raise TimeoutError("Timed out waiting for graph completion")
|
2767
|
+
|
2768
|
+
def ping(self) -> Dict[str, Any]:
|
2769
|
+
"""Simple health-check call to the server (``/ping``).
|
2770
|
+
|
2771
|
+
Returns
|
2772
|
+
-------
|
2773
|
+
Dict[str, Any]
|
2774
|
+
The JSON payload returned by the server, typically
|
2775
|
+
``{"status": "ok", "message": "Server is running"}``.
|
2776
|
+
"""
|
2777
|
+
return self._request("GET", "ping")
|
2778
|
+
|
2779
|
+
# ------------------------------------------------------------------
|
2780
|
+
# Chat API ----------------------------------------------------------
|
2781
|
+
# ------------------------------------------------------------------
|
2782
|
+
def get_chat_history(self, chat_id: str) -> List[Dict[str, Any]]:
|
2783
|
+
"""Return the full message history for the given *chat_id*.
|
2784
|
+
|
2785
|
+
Parameters
|
2786
|
+
----------
|
2787
|
+
chat_id:
|
2788
|
+
Identifier of the chat conversation returned by previous
|
2789
|
+
calls that used ``chat_id``.
|
2790
|
+
"""
|
2791
|
+
return self._request("GET", f"chat/{chat_id}")
|
2792
|
+
|
2793
|
+
def list_chat_conversations(self, limit: int = 100) -> List[Dict[str, Any]]:
|
2794
|
+
"""List recent chat conversations available to the current user.
|
2795
|
+
|
2796
|
+
Parameters
|
2797
|
+
----------
|
2798
|
+
limit:
|
2799
|
+
Maximum number of conversations to return (1-500).
|
2800
|
+
"""
|
2801
|
+
limit_capped = max(1, min(limit, 500))
|
2802
|
+
return self._request("GET", "chats", params={"limit": limit_capped})
|
2803
|
+
|
2804
|
+
# ------------------------------------------------------------------
|
2805
|
+
# Usage API ---------------------------------------------------------
|
2806
|
+
# ------------------------------------------------------------------
|
2807
|
+
def get_usage_stats(self) -> Dict[str, int]:
|
2808
|
+
"""Return cumulative usage statistics for the authenticated user."""
|
2809
|
+
return self._request("GET", "usage/stats")
|
2810
|
+
|
2811
|
+
def get_recent_usage(
|
2812
|
+
self,
|
2813
|
+
operation_type: Optional[str] = None,
|
2814
|
+
since: Optional["datetime"] = None,
|
2815
|
+
status: Optional[str] = None,
|
2816
|
+
) -> List[Dict[str, Any]]:
|
2817
|
+
"""Return recent usage records with optional filtering."""
|
2818
|
+
from datetime import datetime # Local import ensures small dependency surface
|
2819
|
+
|
2820
|
+
params: Dict[str, Any] = {}
|
2821
|
+
if operation_type:
|
2822
|
+
params["operation_type"] = operation_type
|
2823
|
+
if since:
|
2824
|
+
# Accept either ``str`` or ``datetime`` for *since*
|
2825
|
+
params["since"] = since.isoformat() if isinstance(since, datetime) else str(since)
|
2826
|
+
if status:
|
2827
|
+
params["status"] = status
|
2828
|
+
return self._request("GET", "usage/recent", params=params)
|
2829
|
+
|
2830
|
+
# ------------------------------------------------------------------
|
2831
|
+
# Graph helpers -----------------------------------------------------
|
2832
|
+
# ------------------------------------------------------------------
|
2833
|
+
def get_graph_visualization(
|
2834
|
+
self,
|
2835
|
+
name: str,
|
2836
|
+
folder_name: Optional[Union[str, List[str]]] = None,
|
2837
|
+
end_user_id: Optional[str] = None,
|
2838
|
+
) -> Dict[str, Any]:
|
2839
|
+
"""Fetch nodes & links for visualising *name* graph."""
|
2840
|
+
params: Dict[str, Any] = {}
|
2841
|
+
if folder_name is not None:
|
2842
|
+
params["folder_name"] = folder_name
|
2843
|
+
if end_user_id is not None:
|
2844
|
+
params["end_user_id"] = end_user_id
|
2845
|
+
return self._request("GET", f"graph/{name}/visualization", params=params)
|
2846
|
+
|
2847
|
+
def check_workflow_status(self, workflow_id: str, run_id: Optional[str] = None) -> Dict[str, Any]:
|
2848
|
+
"""Poll the status of an asynchronous graph build/update workflow."""
|
2849
|
+
params = {"run_id": run_id} if run_id else None
|
2850
|
+
return self._request("GET", f"graph/workflow/{workflow_id}/status", params=params)
|
2851
|
+
|
2852
|
+
# ------------------------------------------------------------------
|
2853
|
+
# Document download helpers ----------------------------------------
|
2854
|
+
# ------------------------------------------------------------------
|
2855
|
+
def get_document_download_url(self, document_id: str, expires_in: int = 3600) -> Dict[str, Any]:
|
2856
|
+
"""Generate a presigned download URL for a document stored remotely."""
|
2857
|
+
return self._request(
|
2858
|
+
"GET", f"documents/{document_id}/download_url", params={"expires_in": expires_in}
|
2859
|
+
)
|
@@ -1,16 +1,14 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: morphik
|
3
|
-
Version: 0.2.
|
3
|
+
Version: 0.2.1
|
4
4
|
Summary: Morphik Python Client
|
5
5
|
Author-email: Morphik <founders@morphik.ai>
|
6
6
|
Requires-Python: >=3.8
|
7
|
-
Requires-Dist: build>=1.2.2.post1
|
8
7
|
Requires-Dist: httpx>=0.24.0
|
9
8
|
Requires-Dist: pillow>=10.4.0
|
10
9
|
Requires-Dist: pydantic>=2.10.3
|
11
10
|
Requires-Dist: pyjwt>=2.0.0
|
12
11
|
Requires-Dist: requests>=2.32.3
|
13
|
-
Requires-Dist: twine>=6.1.0
|
14
12
|
Description-Content-Type: text/markdown
|
15
13
|
|
16
14
|
# Morphik
|
@@ -1,10 +1,10 @@
|
|
1
|
-
morphik/__init__.py,sha256=
|
1
|
+
morphik/__init__.py,sha256=hUNHM6uAWKjgTUETBA0VeVb1rWoT_ncknW5Id-SPCuY,242
|
2
2
|
morphik/_internal.py,sha256=pV1dbZZ8ab7bchAAdqqDbJcOeu_vM6TnNtjY6tS-wDY,19650
|
3
|
-
morphik/async_.py,sha256=
|
3
|
+
morphik/async_.py,sha256=26SM1TjOahLk-x4eyY1elQLsoLETGnQbBATYUYqDayM,101405
|
4
4
|
morphik/exceptions.py,sha256=v4XGmfq5B0KrZEF6M1ID8A50-45-SRAQZTrXGXM6n0Q,260
|
5
5
|
morphik/models.py,sha256=JFMeGLbEke-Bls08JXCBv3y_z4eI3PBW_mbX-989i5I,20942
|
6
6
|
morphik/rules.py,sha256=fw0RovS0Pwtff8Dvo3nkM3Wl6WtR3ykSaxsU_sxdXKI,2565
|
7
|
-
morphik/sync.py,sha256=
|
7
|
+
morphik/sync.py,sha256=kC8oAlzzUFO6n8my_cnEIVT7U5MCye67dau8kVbeLJI,106182
|
8
8
|
morphik/tests/README.md,sha256=jtJDDK8cS5E4SbygFQDy7t6Y-kQwNYtZajRwVJDR62U,1069
|
9
9
|
morphik/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
10
|
morphik/tests/example_usage.py,sha256=ls8n7355q-8gY43pZLKd4SzI-01MdFeXbT8bZ4U8MCg,11561
|
@@ -13,6 +13,6 @@ morphik/tests/test_sync.py,sha256=Reqa25Q259mCr-tzWzc1RDcs5KZuDfBkJRKOyyxhDtE,13
|
|
13
13
|
morphik/tests/test_docs/sample1.txt,sha256=Fx6TElSiKdxyFeBp1iHthzHctFVZm38DrqcbdZMoidY,507
|
14
14
|
morphik/tests/test_docs/sample2.txt,sha256=PE97gPv59J27A7CSNvi_0tRBIN3Mj6pyTFElCLfs3TE,686
|
15
15
|
morphik/tests/test_docs/sample3.txt,sha256=OzrnJ_XsDUntEV0jk-ansa3_KIa6GnpvS5EVmlh6BHo,732
|
16
|
-
morphik-0.2.
|
17
|
-
morphik-0.2.
|
18
|
-
morphik-0.2.
|
16
|
+
morphik-0.2.1.dist-info/METADATA,sha256=ej62vqMtwpxsaVdL8ExdDqs68hicO3FrG1X8dd-qSDk,3377
|
17
|
+
morphik-0.2.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
18
|
+
morphik-0.2.1.dist-info/RECORD,,
|
File without changes
|