SDK for Momento
Project description
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.
- Website: https://www.gomomento.com/
- Momento Documentation: https://docs.momentohq.com/
- Getting Started: https://docs.momentohq.com/getting-started
- Python SDK Documentation: https://docs.momentohq.com/sdks/python
- Discuss: Momento Discord
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
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
Built Distribution
File details
Details for the file momento-1.23.5.tar.gz
.
File metadata
- Download URL: momento-1.23.5.tar.gz
- Upload date:
- Size: 80.8 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e0456aeb4a3ebb1c4d078cd0ac7faf0d2a9a88f1d290d47bbbc65c390179247 |
|
MD5 | 2af75ba1f2fcd9c170f9a16f54d9f341 |
|
BLAKE2b-256 | e7d26082a7c6291d0b5de1119182298fc0472b608386f06964f2590932d99b7c |
File details
Details for the file momento-1.23.5-py3-none-any.whl
.
File metadata
- Download URL: momento-1.23.5-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | f634c9013d6c01026776df8843bb10c337e711b804c166171f13157986266eb4 |
|
MD5 | c6ab4e5b5308dd4506f0cbf0ec0fb70a |
|
BLAKE2b-256 | 46fe54ca16a6d0e0d28e3cce362d54e8c87a72a9be1ff64bd07b552a6b6f9743 |