Skip to main content

Smart Hashmap

Lint and Test Smart Hashmap logo

Wrapper for key-value based storage systems. Provides convenient way to organize data for quick searching.

Installation

1. Using pip: pip install smart_hashmap

2. Building from source: make install

How to use

Firstly you need to register methods:

from smart_hashmap.cache import Cache

Cache.register_get_method(YOUR_GET_METHOD)
Cache.register_set_method(YOUR_SET_METHOD)
Cache.register_update_method(YOUR_UPDATE_METHOD)
Cache.register_delete_method(YOUR_DELETE_METHOD)

NOTE: Methods signature MUST match their placeholders signature

GET_METHOD = lambda cache, name, key, default=None: None  # noqa: E731
SET_METHOD = lambda cache, name, key, value: None  # noqa: E731
UPDATE_METHOD = lambda cache, name, key, value: None  # noqa: E731
DELETE_METHOD = lambda cache, name, key: None  # noqa: E731
"""METHODS placeholders. You should register yours."""

Now you are all set up to use Cache.search

How it works

In default setup Cache creates and maintains indexes based on Cache.primary_key.

So every object save in cache MUST have such key. (By default its _id)

On every called action for example Cache.update Cache looks in pipeline Cache.PIPELINE.update for middlewares to run before and after main function execution. For example in current situation after .update function execution indexing middleware will check if documents fields matching its keys were changed. If so it will get index data, look for old values in value.__shadow_copy__ remove such index data and create new record with updated values.

Adding middlewares

Adding new action is easy:

from smart_hashmap.cache import Cache, PipelineContext

@Cache.PIPELINE.set.before()
def add_my_field(ctx: PipelineContext):

    key, value = ctx.args
    value["my_field"] = 1

Now every cache value saved with Cache.set will be added 'my_field' before main function execution.

Custom Indexes

To create custom index you need to simply create new subclass of Index.

from smart_hashmap.index import Index

class IndexByModel(Index):
    keys = ["_id", "model"]

NOTE: After that all values MUST have fields _id AND model

NOTE: Primary key MUST ALWAYS be in keys

Searching

After all required indexes created - searching will be as quick as possible.

from smart_hashmap.cache import Cache
from smart_hashmap.index import Index

class IndexByModel(Index):
    keys = ["_id", "model"]

cache = Cache()
cache.search("my_cache", {"model": "1.0"})

When .search is called it will firstly check for indexes containing search fields. After finding best index, it will get index data and find matching primary keys. Now searching is as easy as getting values by their key.

Metadata

Release files for smart-hashmap 1.0.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 smart-hashmap 1.0.4
File Size Uploaded Provenance Actions
smart_hashmap-1.0.4.tar.gz 6.4 kB Without provenance Details for smart_hashmap-1.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for smart-hashmap 1.0.4
File Interpreter ABI Platform Actions
smart_hashmap-1.0.4-py3-none-any.whl Python 3 none any Details for smart_hashmap-1.0.4-py3-none-any.whl

Total release size: 14.6 kB

Release files / smart_hashmap-1.0.4.tar.gz

Download URL smart_hashmap-1.0.4.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
5d435362caa7a98b48f63c919898f256361ce2557b412b2b115e5370d0b60f42
BLAKE2b-256 checksum
How to use checksums
1a7f33cdc359f1195bb5f192856580c91f8c2b745ea32328bf37a954e1c12a9d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.2.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.6.13

Release files / smart_hashmap-1.0.4-py3-none-any.whl

Download URL smart_hashmap-1.0.4-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b6b23349f6cafe1b73f1d1ae9e13fffd0cf0926bb1d5481231256d7e15ab2e8d
BLAKE2b-256 checksum
How to use checksums
82fbb1af95cff68f1eeec07826134e58c8ad40f30b09c55b6a5e6f0901f6655b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.2.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.6.13

Security for smart-hashmap 1.0.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.

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