Giter Site home page Giter Site logo

vpolikarpov-akvelon / client-sdk-python Goto Github PK

View Code? Open in Web Editor NEW

This project forked from momentohq/client-sdk-python

0.0 0.0 0.0 871 KB

Official Python SDK for Momento Serverless Cache

License: Apache License 2.0

Python 99.56% Makefile 0.44%

client-sdk-python's Introduction

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_AUTH_TOKEN which must be set to a valid Momento authentication token.

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, CacheSet, CreateCache, ListCaches

cache_client = CacheClient(
    Configurations.Laptop.v1(),
    CredentialProvider.from_environment_variable("MOMENTO_AUTH_TOKEN"),
    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, CacheSet, CreateCache

cache_client = CacheClient(
    configuration=Configurations.Laptop.v1(),
    credential_provider=CredentialProvider.from_environment_variable('MOMENTO_AUTH_TOKEN'),
    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!

client-sdk-python's People

Contributors

malandis avatar cprice404 avatar gautamomento avatar schwern avatar eaddingtonwhite avatar nand4011 avatar pgautier404 avatar dependabot[bot] avatar poppoerika avatar kvcache avatar rlinehan avatar virratanasangpunth avatar bruuuuuuuce avatar tylerburdsall avatar mjindalmotiv8 avatar rishtigupta avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.