Python client for the GraphMem knowledge graph API
Project description
anura-graph (Python)
Python client for the GraphMem knowledge graph API.
Installation
pip install anura-graph
Quick Start
from graphmem import GraphMem
mem = GraphMem(api_key="gm_your_key_here")
# Store knowledge
result = mem.remember("Alice works at Acme Corp as a software engineer")
print(f"Extracted {result.extracted_count} facts")
# Retrieve context
ctx = mem.get_context("What does Alice do?")
print(ctx)
# Search for an entity
result = mem.search("Alice")
print(result.edges)
All Methods
Core
| Method | Description |
|---|---|
remember(text) |
Extract knowledge from text and store in the graph |
get_context(query, options?) |
Retrieve graph context for a query |
search(entity) |
Search for an entity and its 1-hop neighbors |
Graph Management
| Method | Description |
|---|---|
get_graph() |
Get the full graph (nodes, edges, communities) |
ingest_triples(triples) |
Ingest triples directly into the graph |
delete_edge(id, blacklist?) |
Delete an edge, optionally blacklisting it |
update_edge_weight(id, weight?, increment?) |
Update an edge's weight |
delete_node(id) |
Delete a node and all its connected edges |
export_graph() |
Export the entire graph as portable JSON |
import_graph(data) |
Import a graph export into the current project |
Traces
| Method | Description |
|---|---|
list_traces(limit?, cursor?) |
List query traces with pagination |
get_trace(id) |
Get details for a specific trace |
Blacklist
| Method | Description |
|---|---|
list_blacklist(limit?, cursor?) |
List blacklisted triples |
add_to_blacklist(subject, predicate, object) |
Add a triple to the blacklist |
remove_from_blacklist(id) |
Remove a triple from the blacklist |
Pending Facts
| Method | Description |
|---|---|
list_pending(limit?, cursor?) |
List pending facts |
approve_fact(id) |
Approve a pending fact |
reject_fact(id, blacklist?) |
Reject a pending fact |
approve_all() |
Approve all pending facts |
reject_all() |
Reject all pending facts |
Projects
| Method | Description |
|---|---|
list_projects() |
List all projects |
create_project(name) |
Create a new project |
delete_project(id) |
Delete a project |
select_project(id) |
Switch active project |
Communities
| Method | Description |
|---|---|
list_communities() |
List all detected communities |
detect_communities() |
Run community detection |
Other
| Method | Description |
|---|---|
health() |
Check server health |
get_usage() |
Get usage and tier info |
Configuration
from graphmem import GraphMem, RetryConfig
mem = GraphMem(
api_key="gm_your_key_here",
base_url="https://graphmem.com", # default
retry=RetryConfig(
max_retries=3, # default
base_delay=0.5, # seconds, default
max_delay=10.0, # seconds, default
retry_on=[429, 500, 502, 503, 504], # default
),
timeout=30.0, # seconds, default
)
Rate Limit Info
After each request, rate limit info is available:
mem.remember("some fact")
print(mem.rate_limit.remaining) # requests remaining
print(mem.rate_limit.limit) # total allowed per window
print(mem.rate_limit.reset) # unix timestamp when window resets
Error Handling
from graphmem import GraphMem, GraphMemError
mem = GraphMem(api_key="gm_your_key_here")
try:
mem.remember("some text")
except GraphMemError as e:
print(f"API error {e.status}: {e}")
print(e.body) # raw response body
Context Manager
The client can be used as a context manager to ensure the HTTP connection is properly closed:
with GraphMem(api_key="gm_your_key_here") as mem:
mem.remember("Alice works at Acme")
ctx = mem.get_context("Alice")
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
anura_graph-0.2.0.tar.gz
(9.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file anura_graph-0.2.0.tar.gz.
File metadata
- Download URL: anura_graph-0.2.0.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d97e9a2dbc704985af974f5fdd6667f0c7b1b5547aeb7d94ae1234e9c0d65b5
|
|
| MD5 |
174ee65817dcb4babb30fbac8eb6d55f
|
|
| BLAKE2b-256 |
13fcc1737fb7e5cd1f45e9b76082ebf98d42798bef1f6cb40baf8376976e27b1
|
File details
Details for the file anura_graph-0.2.0-py3-none-any.whl.
File metadata
- Download URL: anura_graph-0.2.0-py3-none-any.whl
- Upload date:
- Size: 10.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
788586dac2263886b6d969cd87240316d2a87628eb0873aa7044ae48eae14a1f
|
|
| MD5 |
5d8dc9730866c5e80cb7f48538edc3d4
|
|
| BLAKE2b-256 |
64215cfe125cd66a70402f96e2d5309ef51f846bce5613bcc6f66cb3915b7dfc
|