Skip to main content

SDK for Momento

Project description

logo

project status project stability

Momento Python Client Library

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 Python client library.

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.

Usage

The examples below require an environment variable named MOMENTO_API_KEY which must be set to a valid Momento API key. You can get one from the Momento Console.

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_variable("MOMENTO_API_KEY"), 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_variable("MOMENTO_API_KEY"),
    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


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.23.3.tar.gz (80.7 kB view details)

Uploaded Source

Built Distribution

momento-1.23.3-py3-none-any.whl (134.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: momento-1.23.3.tar.gz
  • Upload date:
  • Size: 80.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.12.3 Linux/6.8.0-1014-azure

File hashes

Hashes for momento-1.23.3.tar.gz
Algorithm Hash digest
SHA256 6ce839256066ab95e9ec393d97b05bdf60de028b788c0b8a9215615f056662c9
MD5 5a0adbb0365cd5161a5f0efa8106bb2d
BLAKE2b-256 f374619866d6dfd125a69544042ccca4171ba909421306091d5487e5d806f8f8

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for momento-1.23.3-py3-none-any.whl
Algorithm Hash digest
SHA256 887c4f3b2f2ee865e36217628df02a6645a6acccf8e708ff3f10878bba03bc6e
MD5 fa1030d6fc20aae77b210a5f11abcd54
BLAKE2b-256 d62f49257ca6bf50656652121ba33644ce19538834f5ec73af2fcbb903d97fe1

See more details on using hashes here.

Supported by

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