Skip to main content
Version: 1.7

KeyValueStore

{"content": ["The KeyValueStore class represents a key-value store.\n\nYou can imagine it as a simple data storage that is used\nfor saving and reading data records or files. Each data record is\nrepresented by a unique key and associated with a MIME content type.\n\nDo not instantiate this class directly, use the Actor.open_key_value_store() function instead.\n\nEach crawler run is associated with a default key-value store, which is created exclusively\nfor the run. By convention, the crawler input and output are stored into the\ndefault key-value store under the INPUT and OUTPUT key, respectively.\nTypically, input and output are JSON files, although it can be any other format.\nTo access the default key-value store directly, you can use the\nKeyValueStore.get_value and KeyValueStore.set_value convenience functions.\n\nKeyValueStore stores its data either on local disk or in the Apify cloud,\ndepending on whether the APIFY_LOCAL_STORAGE_DIR or APIFY_TOKEN environment variables are set.\n\nIf the APIFY_LOCAL_STORAGE_DIR environment variable is set, the data is stored in\nthe local directory in the following files:\n``\n{APIFY_LOCAL_STORAGE_DIR}/key_value_stores/{STORE_ID}/{INDEX}.{EXT}\n``", "Note that {STORE_ID} is the name or ID of the key-value store. The default key-value store has ID: default,\nunless you override it by setting the APIFY_DEFAULT_KEY_VALUE_STORE_ID environment variable.\nThe {KEY} is the key of the record and {EXT} corresponds to the MIME content type of the data value.\n\nIf the APIFY_TOKEN environment variable is set but APIFY_LOCAL_STORAGE_DIR is not, the data is stored in the\nApify Key-value store cloud storage."]}

Index

Methods

drop

  • async drop(): None
  • {"content": ["Remove the key-value store either from the Apify cloud storage or from the local directory."]}


    Returns None

get_public_url

  • async get_public_url(key): str
  • {"content": ["Get a URL for the given key that may be used to publicly access the value in the remote key-value store.\n", {"


    Parameters

    • key: str

    Returns str

get_value

  • async get_value(key, default_value): T | None
  • {"content": ["Get a value from the key-value store.\n", {"


    Parameters

    • key: str
    • default_value: T | None = None

    Returns T | None

iterate_keys

  • async iterate_keys(exclusive_start_key): AsyncIterator[IterateKeysTuple]
  • {"content": ["Iterate over the keys in the key-value store.\n", {"


    Parameters

    • exclusive_start_key: str | None = None

    Returns AsyncIterator[IterateKeysTuple]

open

  • {"content": ["Open a key-value store.\n\nKey-value stores are used to store records or files, along with their MIME content type.\nThe records are stored and retrieved using a unique key.\nThe actual data is stored either on a local filesystem or in the Apify cloud.\n", {"


    Parameters

    • keyword-onlyid: str | None = None
    • keyword-onlyname: str | None = None
    • keyword-onlyforce_cloud: bool = False
    • keyword-onlyconfig: Configuration | None = None

    Returns KeyValueStore

set_value

  • async set_value(key, value, content_type): None
  • {"content": ["Set or delete a value in the key-value store.\n", {"


    Parameters

    • key: str
    • value: Any
    • content_type: str | None = None

    Returns None