handler with pd.inputs["data_store"].
Adding a Data Store
Click Add Data Store near the top of a Python step:
Saving data
Data stores are key-value stores. Saving data within a data store is just like setting a property on a dictionary:Setting expiration (TTL) for records
You can set an expiration time for a record by passing a TTL (Time-To-Live) option as the third argument to theset method. The TTL value is specified in seconds:
Updating TTL for existing records
You can update the TTL for an existing record using theset_ttl method:
Retrieving keys
Fetch all the keys in a given data store using thekeys method:
Checking for the existence of specific keys
If you need to check whether a specifickey exists in a data store, use if and in as a conditional:
Retrieving data
Data stores are very performant at retrieving single records by keys. However you can also use key iteration to retrieve all records within a Data Store as well.Data stores are intended to be a fast and convenient data storage option for quickly adding data storage capability to your workflows without adding another database dependency.However, if you need more advanced querying capabilities for querying records with nested dictionaries or filtering based on a record value - consider using a full fledged database. Pipedream can integrate with MySQL, Postgres, DynamoDb, MongoDB and more.
Get a single record
You can retrieve single records from a data store by key:data_store.get() method to retrieve a specific key’s contents:
What’s the difference between
data_store["key"] and data_store.get("key")?data_store["key"]will throw aTypeErrorif the key doesn’t exist in the data store.data_store.get("key")will instead returnNoneif the key doesn’t exist in the data store.data_store.get("key", "default_value")will return"default_value"if the key doesn’t exist on the data store.
Retrieving all records
You can retrieve all records within a data store by using an async iterator:Deleting or updating values within a record
To delete or update the value of an individual record, assignkey a new value or '' to remove the value but retain the key.
Working with nested dictionaries
You can store dictionaries within a record. This allows you to create complex records. However, to update specific attributes within a nested dictionary, you’ll need to replace the record entirely. For example, the code the below will not update thename attribute on the stored dictionary stored under the key pokemon:
Deleting specific records
To delete individual records in a data store, use thedel operation for a specific key:
Deleting all records from a specific data store
If you need to delete all records in a given data store, you can use theclear method.
Viewing store data
You can view the contents of your data stores in your Pipedream dashboard. From here you can also manually edit your data store’s data, rename stores, delete stores or create new stores.Workflow counter example
You can use a data store as a counter. For example, this code counts the number of times the workflow runs:Dedupe data example
Data Stores are also useful for storing data from prior runs to prevent acting on duplicate data, or data that’s been seen before. For example, this workflow’s trigger contains an email address from a potential new customer. But we want to track all emails collected so we don’t send a welcome email twice:TTL use case: temporary caching and rate limiting
TTL functionality is particularly useful for implementing temporary caching and rate limiting. Here’s an example of a simple rate limiter that prevents a user from making more than 5 requests per hour:- Session tokens with automatic expiration
- Short-lived feature flags
- Temporary access grants
- Time-based promotional codes
Supported data types
Data stores can hold any JSON-serializable data within the storage limits. This includes data types including:- Strings
- Dictionaries
- Lists
- Integers
- Floats