Skip to main content

Python client for the GraphMem knowledge graph API

Project description

anura-graph (Python)

Python client for the AnuraMemory 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://anuramemory.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.1.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

anura_graph-0.2.1-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file anura_graph-0.2.1.tar.gz.

File metadata

  • Download URL: anura_graph-0.2.1.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

Hashes for anura_graph-0.2.1.tar.gz
Algorithm Hash digest
SHA256 ef66f2a0660d3214685dacfd65b1894841abb52eecbd8ab7a71e1620ad0d61be
MD5 aad508b371b21ec98d6910a37d661b8e
BLAKE2b-256 6e87b2495bc170925a7729a636839cb6be7aa078b3aa33649d6edf710231ad27

See more details on using hashes here.

File details

Details for the file anura_graph-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: anura_graph-0.2.1-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

Hashes for anura_graph-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 eb5ac3b01ce3626e35b30e791caee1c7546b523abc60d150efd754604c0d6ff6
MD5 0eb97415ecebfb9fb6845e8c1183d491
BLAKE2b-256 08b8045426393ca826a913053bdb7ed552ae5ff9cfb4c7b916b9985ddc2df958

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page