Skip to main content

graphcache

Python Library to store connected nodes and their properties on cache storage (redis)

Installation

To install graphcache, simply:

pip install graphcache

Development

  • Install pyenv and pyenv-virtualenv
  • Run
    pyenv install 3.7.0 --skip-existing
    pyenv virtualenv 3.7.0 graphcache
    
  • Update requirements
    pip install -r requirements.txt
    
  • Install Redis

Basic Use

Ensure you have redis service running
On macos

redis-server /usr/local/etc/redis.conf

To use graphcache, you must first create an instance of GraphCache, and construct your nodes and edges:

# Import GraphCache
from graphcache import GraphCache

# default 
# host = localhost
# port = 6379
# db = 0
g = GraphCache(host='localhost', port=6379, db=0)

# Add optimisation keys
g.optimise_for('bananas')
g.optimise_for('apples')

# Create Nodes (need 'apples', 'bananas' keys in all nodes, as they have been added to optimisation_keys)
n1 = g.add_vertex({
    'name': 'Tom',
    'age': 24,
    'bananas': 5,
    'apples': 4
})
n2 = g.add_vertex({
    'name': 'Bob',
    'bananas': 0,
    'apples': 8
})
n3 = g.add_vertex({
    'name': 'Harry',
    'gender': 'Male',
    'bananas': 3,
    'apples': 1
})
n4 = g.add_vertex({
    'name': 'Jill',
    'bananas': 8,
    'apples': 1
})

# Connect them
g.add_edge(g.entry, n2) # g.entry specifies the entry point for graph
g.add_edge(g.entry, n3)
g.add_edge(n2, n3)
g.add_edge(n3, n4)
g.add_edge(n2, n1)

graphcache

Then you can perform filter/sort operations on any of the node to get the required adjacent nodes from that node:

# Filter By
# Get all outgoing nodes (only adjacent) from n2 which have only 1 apples
nodes1 = n2.get_outgoing().filter_by('apples', [1]).get_all_nodes()

# Sort By
# Get all incoming nodes (only adjacent) to n3 sorted by number of bananas they have
nodes2 = n3.get_incoming().sort_by('bananas').get_all_nodes()

# Get first incoming node to n1 sorted by bananas
node1 = n1.get_incoming().sort_by('bananas').get_node_indexed_at(0)

Also you can perform chained complex operations:

# Filter By, Sort By
# Get all outgoing nodes (only adjacent) from n2 with apples less than 5 and sorted by bananas
nodes1 = n2.get_outgoing().filter_by('apples', 5, "lt").sort_by('bananas').get_all_nodes()

# Sort By, Filter By, Filter By
nodes2 = n3.get_incoming().sort_by('bananas').filter_by('bananas', [1, 5], "in").filter_by('apples', [1]).get_all_nodes()

Get the key for the graphcache object

g.cache_key
# graphcache-MZ5SQR

Retrieve previously stored graphcache object from redis cache (cache_key = graphcache-MZ5SQR)

# using default redis connection
# host = localhost
# port = 6379
# db = 0
g1 = GraphCache(graphcache_ref='graphcache-MZ5SQR')

Metadata

Release files for graphcache 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for graphcache 0.1.4
File Size Uploaded Provenance Actions
graphcache-0.1.4.tar.gz 9.2 kB Without provenance Details for graphcache-0.1.4.tar.gz

Release files / graphcache-0.1.4.tar.gz

Download URL graphcache-0.1.4.tar.gz
Size 9.2 kB
Tags Source
SHA-256 checksum
How to use checksums
68eaacbf0a3813d5205e261ebd798a8cf263c3f87768131b0195d43b65fe8a23
BLAKE2b-256 checksum
How to use checksums
2b11c4ecdd69850165b353b2cff1153cbfc365450ddfa8b921892bd9d268b843
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.0

Security for graphcache 0.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.4 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page