libro-sdk 0.1.0__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.
libro/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ from .client import LibroClient
2
+
3
+ __all__ = ["LibroClient"]
libro/client.py ADDED
@@ -0,0 +1,77 @@
1
+ import os
2
+ import requests
3
+ from typing import Dict, Any, List, Optional
4
+
5
+ class LibroError(Exception):
6
+ """Base exception for Libro SDK errors."""
7
+ pass
8
+
9
+ class LibroClient:
10
+ def __init__(self, api_key: Optional[str] = None, base_url: str = "https://api.libro.ai"):
11
+ self.api_key = api_key or os.environ.get("LIBRO_API_KEY")
12
+ if not self.api_key:
13
+ raise ValueError("API key is required. Pass it to the client or set LIBRO_API_KEY env var.")
14
+
15
+ # Remove trailing slash
16
+ self.base_url = base_url.rstrip("/")
17
+ self.session = requests.Session()
18
+ self.session.headers.update({
19
+ "Authorization": f"Bearer {self.api_key}",
20
+ "Content-Type": "application/json"
21
+ })
22
+
23
+ def ingest(self, user_id: str, text: str, metadata: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
24
+ """Ingest a new memory for a user."""
25
+ payload = {"userId": user_id, "text": text}
26
+ if metadata is not None:
27
+ payload["metadata"] = metadata
28
+
29
+ res = self.session.post(f"{self.base_url}/api/v1/ingest", json=payload)
30
+ self._check_response(res)
31
+ return res.json()
32
+
33
+ def get_context(self, user_id: str, query: str) -> Dict[str, Any]:
34
+ """Retrieve relevant context for a user based on a query."""
35
+ payload = {"userId": user_id, "query": query}
36
+ res = self.session.post(f"{self.base_url}/api/v1/get-context", json=payload)
37
+ self._check_response(res)
38
+ return res.json()
39
+
40
+ def forget(self, user_id: str, memory_id: Optional[str] = None, query: Optional[str] = None) -> Dict[str, Any]:
41
+ """Delete a specific memory by ID, or memories matching a query for a user."""
42
+ if not memory_id and not query:
43
+ raise ValueError("Must provide either memory_id or query to forget.")
44
+
45
+ payload = {"userId": user_id}
46
+ if memory_id:
47
+ payload["memoryId"] = memory_id
48
+ if query:
49
+ payload["query"] = query
50
+
51
+ res = self.session.post(f"{self.base_url}/api/v1/forget", json=payload)
52
+ self._check_response(res)
53
+ return res.json()
54
+
55
+ def update(self, user_id: str, memory_id: str, text: Optional[str] = None, metadata: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
56
+ """Update an existing memory's text or metadata."""
57
+ if not text and not metadata:
58
+ raise ValueError("Must provide either text or metadata to update.")
59
+
60
+ payload = {"userId": user_id, "memoryId": memory_id}
61
+ if text:
62
+ payload["text"] = text
63
+ if metadata is not None:
64
+ payload["metadata"] = metadata
65
+
66
+ res = self.session.post(f"{self.base_url}/api/v1/update", json=payload)
67
+ self._check_response(res)
68
+ return res.json()
69
+
70
+ def _check_response(self, response: requests.Response):
71
+ if not response.ok:
72
+ try:
73
+ err_data = response.json()
74
+ msg = err_data.get("error", response.text)
75
+ except Exception:
76
+ msg = response.text
77
+ raise LibroError(f"API Error {response.status_code}: {msg}")
@@ -0,0 +1,45 @@
1
+ Metadata-Version: 2.4
2
+ Name: libro-sdk
3
+ Version: 0.1.0
4
+ Summary: Official Python SDK for the Libro AI memory infrastructure.
5
+ Author: Libro Team
6
+ Requires-Python: >=3.8
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: requests>=2.25.0
9
+ Provides-Extra: dev
10
+ Requires-Dist: pytest>=7.0; extra == "dev"
11
+ Requires-Dist: mypy>=1.0; extra == "dev"
12
+
13
+ # Libro Python SDK
14
+
15
+ Official Python SDK for Libro, the open-source AI memory infrastructure.
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ pip install libro-sdk
21
+ ```
22
+
23
+ ## Quick Start
24
+
25
+ ```python
26
+ from libro import LibroClient
27
+
28
+ # Initialize the client
29
+ client = LibroClient(api_key="your_api_key", base_url="http://localhost:3000")
30
+
31
+ # 1. Ingest a memory
32
+ client.ingest(
33
+ user_id="user_123",
34
+ text="User prefers Python over Java",
35
+ metadata={"source": "slack"}
36
+ )
37
+
38
+ # 2. Retrieve context
39
+ context = client.get_context(
40
+ user_id="user_123",
41
+ query="What programming language do they like?"
42
+ )
43
+
44
+ print(context)
45
+ ```
@@ -0,0 +1,6 @@
1
+ libro/__init__.py,sha256=U5gE770Nq03ZujANFc4Wpmm6-XOBT_wZAghqStybE_s,59
2
+ libro/client.py,sha256=sadhVO1Jj0cZIapB47QAGXil7VZ4mvkZQmoneK_NH4M,3160
3
+ libro_sdk-0.1.0.dist-info/METADATA,sha256=9sjQrpB-6ckjXGacUDEiTugfQz2lnJwBONpBkEj_oP0,936
4
+ libro_sdk-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
5
+ libro_sdk-0.1.0.dist-info/top_level.txt,sha256=aPNst6WSPRjN2wqWLHriT_bE2asBn6LnUNeaLh2kGMc,6
6
+ libro_sdk-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ libro