Getting Started with Momento Cache in Python
If you need to get going quickly with Python and Momento Cache, this page contains the basic API calls you'll need.
If you combine all of the functions on this page into one python file, you'd have a central collection of functions you can import and call from other python code. In addition, if you are using this code in production you might look to replace the print() calls with ones using the logging library (import logging
) in python. Click here to see the class file with all definitions in it.
Install the Momento SDK
The Momento Python SDK is available on pypi as momento
.
To install in your Python application via pip, use:
pip install momento
Set up your API key
You'll need a Momento API key to authenticate with Momento. You can get one, preferably a fine-grained token, from the Momento Web Console. Once you have a token, store it in an environment variable so that the Momento client can consume it:
export MOMENTO_API_KEY=<your Momento token here>
Note: it is best practice to put the token into something like AWS Secret Manager or GCP Secret Manager instead of an environment variable for enhanced security, but we are using one here for demo purposes.