Skip to main content

SDK for Momento

Project description

logo

project status project stability

Momento Client Library for Python

Momento Cache is a fast, simple, pay-as-you-go caching solution without any of the operational overhead required by traditional caching solutions. This repo contains the source code for the Momento client library for Python.

To get started with Momento you will need a Momento Auth Token. You can get one from the Momento Console.

Packages

The Momento Python SDK package is available on pypi: momento.

Prerequisites

Usage

Python 3.10 introduced the match statement, which allows for structural pattern matching on objects. If you are running python 3.10 or greater, here is a quickstart you can use in your own project:

from datetime import timedelta

from momento import CacheClient, Configurations, CredentialProvider
from momento.responses import CacheGet

cache_client = CacheClient(
    Configurations.Laptop.v1(), CredentialProvider.from_environment_variables_v2(), timedelta(seconds=60)
)

cache_client.create_cache("cache")
cache_client.set("cache", "my-key", "my-value")
get_response = cache_client.get("cache", "my-key")
match get_response:
    case CacheGet.Hit() as hit:
        print(f"Got value: {hit.value_string}")
    case _:
        print(f"Response was not a hit: {get_response}")

The above code uses structural pattern matching, a feature introduced in Python 3.10. Using a Python version less than 3.10? No problem. Here is the same example compatible across all versions of Python:

from datetime import timedelta

from momento import CacheClient, Configurations, CredentialProvider
from momento.responses import CacheGet

cache_client = CacheClient(
    configuration=Configurations.Laptop.v1(),
    credential_provider=CredentialProvider.from_environment_variables_v2(),
    default_ttl=timedelta(seconds=60),
)
cache_client.create_cache("cache")
cache_client.set("cache", "myKey", "myValue")
get_response = cache_client.get("cache", "myKey")
if isinstance(get_response, CacheGet.Hit):
    print(f"Got value: {get_response.value_string}")

Getting Started and Documentation

Documentation is available on the Momento Docs website.

Examples

Working example projects, with all required build configuration files, are available for both Python 3.10 and up and Python versions before 3.10:

Developing

If you are interested in contributing to the SDK, please see the CONTRIBUTING docs.


For more info, visit our website at https://gomomento.com!

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

momento-1.28.1.tar.gz (90.4 kB view details)

Uploaded Source

Built Distribution

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

momento-1.28.1-py3-none-any.whl (149.5 kB view details)

Uploaded Python 3

File details

Details for the file momento-1.28.1.tar.gz.

File metadata

  • Download URL: momento-1.28.1.tar.gz
  • Upload date:
  • Size: 90.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.12.3 Linux/6.11.0-1018-azure

File hashes

Hashes for momento-1.28.1.tar.gz
Algorithm Hash digest
SHA256 257f385ee4dfaaff651a4ea5766bfa4d4cd63892e51c0c0e3c392446bf493466
MD5 4f7010b2e1b2fdac0de6fd5669f70127
BLAKE2b-256 ec8550a19abeba46c769c140c357d5069f1b1222ec49f0b360c064634ee54214

See more details on using hashes here.

File details

Details for the file momento-1.28.1-py3-none-any.whl.

File metadata

  • Download URL: momento-1.28.1-py3-none-any.whl
  • Upload date:
  • Size: 149.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.12.3 Linux/6.11.0-1018-azure

File hashes

Hashes for momento-1.28.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1651df2cd2b89f0281532ecd502815d07a548bbe4bf841dbf6b164e9a0205eb0
MD5 b4d8b42586f7d8d42ec6bf5e553bc070
BLAKE2b-256 6da3356d0dd366953a534a40abd5f3b3ce218eaeb1567c047a4603d7418c23ff

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