Asset
*****

class psynet.asset.Asset(*args, **kwargs)

   Bases: "AssetSpecification", "Base", "SQLMixin"

   Assets represent particular files (or sometimes collections of
   files) that are used within an experiment. It is encouraged to
   register things like audio files and video files as assets so that
   they can be managed appropriately by PsyNet's deploy and export
   mechanisms.

   Parameters:
      * **local_key** (*str*) -- A string identifier for the asset,
        for example ""stimulus"". If provided, this string identifier
        should together with "parent" and "module_id" uniquely
        identify that asset (i.e. no other asset should share that
        combination of properties).

      * **description** (*str*) -- An optional longer string that
        provides further documentation about the asset.

      * **is_folder** (*bool*) -- Whether the asset is a folder.

      * **data_type** (*str*) -- Experimental: the nature of the
        asset's data. Could be used to determine visualization methods
        etc.

      * **extension** (*str*) -- The file extension, if applicable.

      * **parent** (*object*) -- The object that 'owns' the asset, if
        applicable, for example a Participant or a Node.

      * **key_within_module** (*str*) -- A string that uniquely
        identifies the asset within a given module. If left
        unspecified, this will be automatically generated with
        reference to the "parent" and the "local_key" arguments.

      * **key_within_experiment** (*str*) -- A string that uniquely
        identifies the asset within a given experiment. If left
        unspecified, this will be automatically generated with
        reference to the "key_within_module" and the "module_id"
        arguments.

      * **module_id** (*str*) -- The module within which the asset is
        located.

   needs_storage_backend

      Whether the asset type needs a storage backend, e.g. a file
      server, or whether it can do without (e.g. in the case of an
      externally hosted resource accessible by a URL).

      Type:
         bool

   psynet_version

      The version of PsyNet used to create the asset.

      Type:
         str

   created_during_experiment

      Whether the asset was deposited while the experiment was
      running, as opposed to while preparing the deployment. Stored
      assets created during the experiment are included in "psynet
      export".

      Type:
         bool

   deployment_id

      A string used to identify the particular experiment deployment.

      Type:
         str

   deposited

      Whether the asset has been deposited yet.

      Type:
         bool

   export_path

      A relative path that will be used by default when the asset is
      exported.

      Type:
         str

   participant_id

      ID of the participant who 'owns' the asset, if applicable.

      Type:
         int

   content_id

      A token used for checking whether the contents of two assets are
      equivalent. This takes various forms depending on the asset
      type. For a file, the "content_id" would typically be a hash;
      for an externally hosted asset, it would be the URL, etc.

      Type:
         str

   host_path

      The filepath used to host the asset within the storage
      repository, if applicable.

      Type:
         str

   url

      The URL that can be used to access the asset from the
      perspective of the experiment front-end.

      Type:
         str

   storage

      The storage backend used for the asset.

      Type:
         AssetStorage

   async_jobs

      Lists all async jobs that have been created for the asset,
      including completed ones.

      Type:
         list

   participant

      If the parent is a "Participant", returns that participant.

   participants

      Lists all participants associated with the asset.

      Type:
         list

   trial

      If the parent is a "trial", returns that trial.

   trials

      Lists all trials associated with the asset.

      Type:
         list

   node

      If the parent is a "Node", returns that participant.

   nodes

      Lists all nodes associated with the asset.

      Type:
         list

   network

      If the parent is a "Network", returns that participant.

   networks

      Lists all networks associated with the asset.

      Type:
         list

   errors

      Lists the errors associated with the asset.

      Type:
         list


   Linking assets to other database objects
   ========================================

   PsyNet assets may be linked to other database objects. There are
   two kinds of links that may be used. First, an asset may possess a
   *parent*. This parental relationship is strict in the sense that an
   asset may not possess more than one parent.

   However, in addition to the parental relationship, it is possible
   to link the asset to an arbitrary number of additional database
   objects. These latter links have a key-value construction, meaning
   that one can access a given asset by reference to a given key, for
   example: "node.assets["response"]".

   Importantly, the same asset can have different keys for different
   objects; for example, it might be the "response" for one node, but
   the "stimulus" for another node. These latter relationships are
   instantiated with logic like the following:

      participant.assets["stimulus"] = my_asset

   access_url(subpath=None)

      Return the live PsyNet URL for this asset's access token.

      Return type:
         "str"

   property async_processes

      Deprecated alias of "async_jobs".

   creation_time

      the time at which the Network was created.

   delete_input()

      Deletes the input file(s) that make(s) up the asset.

   deposit(storage=None, async_=False, delete_input=False)

      Parameters:
         * **storage** -- If set to an "AssetStorage" object, the
           asset will be deposited to the provided storage location
           rather than defaulting to the Experiment class's storage
           location.

         * **async** -- If set to "True", then the asset deposit will
           be performed asynchronously and the program's execution
           will continue without waiting for the deposit to complete.
           It is sensible to set this to "True" if you see that the
           participant interface is being held up noticeably by
           waiting for the deposit to complete.

         * **delete_input** ("bool") -- If set to "True", then the
           input file will be deleted after it has been deposited.

   details

      a generic column for storing structured JSON data

   ensure_keys_and_paths()

      Fill in missing key fields and derived paths for the asset.

      For deposited assets, this method preserves existing
      "host_path"/ "object_path"/"url" values (and only fills them if
      missing) so the storage identity does not change.

   failed = None

      boolean indicating whether the Network has failed which prompts
      Dallinger to ignore it unless specified otherwise. Objects are
      usually failed to indicate something has gone wrong.

   failed_reason = None

      an optional reason the object was failed. If the object is
      failed as part of a cascading failure triggered from another
      object, the chain of objects will be captured in this field.

   id

      a unique number for every entry. 1, 2, 3 and so on...

   prepare_for_deployment(registry)

      Runs in advance of the experiment being deployed to the remote
      server.

   property1

      a generic column that can be used to store experiment-specific
      details in String form.

   property2

      a generic column that can be used to store experiment-specific
      details in String form.

   property3

      a generic column that can be used to store experiment-specific
      details in String form.

   property4

      a generic column that can be used to store experiment-specific
      details in String form.

   property5

      a generic column that can be used to store experiment-specific
      details in String form.

   registry

   rotate_access_token()

      Replace the access token and refresh "url".

      Return type:
         "str"

   serve(subpath=None)

      Serve this asset's bytes for an HTTP response.

      Parameters:
         **subpath** (*str**, **optional*) -- Relative path within a
         folder asset.

   set_keys()

      Deprecated. Use "ensure_keys_and_paths()" instead.

   time_of_death = None

      the time at which failing occurred

   type

   update_metadata(parent, local_key, definition=None, module_id=None)

      Update parent-related metadata when linking an asset.

      Parent-related metadata includes the asset's parent object, its
      link key ("local_key"), the parent "module_id" used for key
      generation, and any trial/node definition used to parameterize
      on-demand assets.

      For undeposited assets, this overwrites
      parent/key/module/definition metadata so the asset is bound to
      the current owner. Deposited assets retain existing metadata to
      preserve their storage identity, but missing parent/link fields
      are filled in so exported paths remain unique.

      Parameters:
         * **parent** (*object*) -- The parent object to which the
           asset is linked.

         * **local_key** (*str*) -- The key under which the asset is
           linked.

         * **definition** (*dict**, **optional*) -- Trial or node
           definition used to populate on-demand asset arguments.

         * **module_id** (*str**, **optional*) -- Module identifier to
           set when missing.

      Returns:
         The updated asset instance.

      Return type:
         Asset

   vars

class psynet.asset.AssetLink(local_key, asset)

   Bases: "object"

   These objects define many-to-many mappings between assets and other
   database objects. When we write something like
   "participant.assets["stimulus"] = my_asset", this creates an object
   subclassing "AssetLink" to represent that relationship.

class psynet.asset.AssetModuleState(*args, **kwargs)

   Bases: "AssetLink", "Base", "SQLMixin"

   asset_id

   creation_time

      the time at which the Network was created.

   details

      a generic column for storing structured JSON data

   local_key

   property1

      a generic column that can be used to store experiment-specific
      details in String form.

   property2

      a generic column that can be used to store experiment-specific
      details in String form.

   property3

      a generic column that can be used to store experiment-specific
      details in String form.

   property4

      a generic column that can be used to store experiment-specific
      details in String form.

   property5

      a generic column that can be used to store experiment-specific
      details in String form.

   type

   vars

class psynet.asset.AssetNetwork(*args, **kwargs)

   Bases: "AssetLink", "Base", "SQLMixin"

   asset_id

   creation_time

      the time at which the Network was created.

   details

      a generic column for storing structured JSON data

   local_key

   property1

      a generic column that can be used to store experiment-specific
      details in String form.

   property2

      a generic column that can be used to store experiment-specific
      details in String form.

   property3

      a generic column that can be used to store experiment-specific
      details in String form.

   property4

      a generic column that can be used to store experiment-specific
      details in String form.

   property5

      a generic column that can be used to store experiment-specific
      details in String form.

   type

   vars

class psynet.asset.AssetNode(*args, **kwargs)

   Bases: "AssetLink", "Base", "SQLMixin"

   asset_id

   creation_time

      the time at which the Network was created.

   details

      a generic column for storing structured JSON data

   local_key

   property1

      a generic column that can be used to store experiment-specific
      details in String form.

   property2

      a generic column that can be used to store experiment-specific
      details in String form.

   property3

      a generic column that can be used to store experiment-specific
      details in String form.

   property4

      a generic column that can be used to store experiment-specific
      details in String form.

   property5

      a generic column that can be used to store experiment-specific
      details in String form.

   type

   vars

class psynet.asset.AssetParticipant(*args, **kwargs)

   Bases: "AssetLink", "Base", "SQLMixin"

   asset_id

   creation_time

      the time at which the Network was created.

   details

      a generic column for storing structured JSON data

   local_key

   property1

      a generic column that can be used to store experiment-specific
      details in String form.

   property2

      a generic column that can be used to store experiment-specific
      details in String form.

   property3

      a generic column that can be used to store experiment-specific
      details in String form.

   property4

      a generic column that can be used to store experiment-specific
      details in String form.

   property5

      a generic column that can be used to store experiment-specific
      details in String form.

   type

   vars

class psynet.asset.AssetSpecification(local_key, key_within_module, key_within_experiment, description)

   Bases: "NullElt"

   A base class for asset specifications. An asset specification
   defines some kind of asset or collection or assets. It can be
   included within an experiment timeline.

   Parameters:
      * **local_key** (*str*) -- A string identifier for the asset,
        for example ""stimulus"". If provided, this string identifier
        should together with "parent" and "module_id" uniquely
        identify that asset (i.e. no other asset should share that
        combination of properties).

      * **description** (*str*) -- An optional longer string that
        provides further documentation about the asset.

class psynet.asset.AssetStorage

   Bases: "object"

   Defines a storage back-end for storing assets.

   check_cache(host_path, is_folder)

      Checks whether the registry can find an asset cached at
      "host_path". The implementation is permitted to make
      optimizations for speed that may result in missed caches, i.e.
      returning "False" when the cache did actually exists. However,
      the implementation should only return "True" if it is certain
      that the asset cache exists.

      Returns:
         * "True" or "False".

   serve(asset, subpath=None)

      Serve a deposited asset for an HTTP response.

      Subclasses should override this to return a Flask response.

class psynet.asset.AssetTrial(*args, **kwargs)

   Bases: "AssetLink", "Base", "SQLMixin"

   asset_id

   creation_time

      the time at which the Network was created.

   details

      a generic column for storing structured JSON data

   local_key

   property1

      a generic column that can be used to store experiment-specific
      details in String form.

   property2

      a generic column that can be used to store experiment-specific
      details in String form.

   property3

      a generic column that can be used to store experiment-specific
      details in String form.

   property4

      a generic column that can be used to store experiment-specific
      details in String form.

   property5

      a generic column that can be used to store experiment-specific
      details in String form.

   type

   vars

exception psynet.asset.AwsCliError

   Bases: "RuntimeError"

class psynet.asset.DebugStorage(*args, **kwargs)

   Bases: "LocalStorage"

   A local storage back-end used for debugging.

   Deprecated since version 11.0.0: Use "LocalStorage" instead.

class psynet.asset.ExternalAsset(*args, **kwargs)

   Bases: "Asset"

   An External Asset is an asset that is not managed by PsyNet. This
   would typically mean some kind of file that is hosted on a remote
   web server and is accessible by a URL.

   Parameters:
      * **url** (*str*) -- The URL at which the external asset may be
        accessed.

      * **local_key** (*str*) -- A string identifier for the asset,
        for example ""stimulus"". If provided, this string identifier
        should together with "parent" and "module_id" uniquely
        identify that asset (i.e. no other asset should share that
        combination of properties).

      * **description** (*str*) -- An optional longer string that
        provides further documentation about the asset.

      * **is_folder** (*bool*) -- Whether the asset is a folder.

      * **data_type** (*str*) -- Experimental: the nature of the
        asset's data. Could be used to determine visualization methods
        etc.

      * **extension** (*str*) -- The file extension, if applicable.

      * **parent** (*object*) -- The object that 'owns' the asset, if
        applicable, for example a Participant or a Node.

      * **key_within_module** (*str*) -- A string that uniquely
        identifies the asset within a given module. If left
        unspecified, this will be automatically generated with
        reference to the "parent" and the "local_key" arguments.

      * **key_within_experiment** (*str*) -- A string that uniquely
        identifies the asset within a given experiment. If left
        unspecified, this will be automatically generated with
        reference to the "key_within_module" and the "module_id"
        arguments.

      * **module_id** (*str*) -- The module within which the asset is
        located.

   psynet_version

      The version of PsyNet used to create the asset.

      Type:
         str

   deployment_id

      A string used to identify the particular experiment deployment.

      Type:
         str

   deposited

      Whether the asset has been deposited yet.

      Type:
         bool

   export_path

      A relative path that will be used by default when the asset is
      exported.

      Type:
         str

   participant_id

      ID of the participant who 'owns' the asset, if applicable.

      Type:
         int

   content_id

      A token used for checking whether the contents of two assets are
      equivalent. This takes various forms depending on the asset
      type. For a file, the "content_id" would typically be a hash;
      for an externally hosted asset, it would be the URL, etc.

      Type:
         str

   host_path

      The filepath used to host the asset within the storage
      repository, if applicable.

      Type:
         str

   url

      The URL that can be used to access the asset from the
      perspective of the experiment front-end.

      Type:
         str

   storage

      The storage backend used for the asset.

      Type:
         AssetStorage

   async_jobs

      Lists all async jobs that have been created for the asset,
      including completed ones.

      Type:
         list

   participant

      If the parent is a "Participant", returns that participant.

   participants

      Lists all participants associated with the asset.

      Type:
         list

   trial

      If the parent is a "trial", returns that trial.

   trials

      Lists all trials associated with the asset.

      Type:
         list

   node

      If the parent is a "Node", returns that participant.

   nodes

      Lists all nodes associated with the asset.

      Type:
         list

   network

      If the parent is a "Network", returns that participant.

   networks

      Lists all networks associated with the asset.

      Type:
         list

   errors

      Lists the errors associated with the asset.

      Type:
         list


   Linking assets to other database objects
   ========================================

   PsyNet assets may be linked to other database objects. There are
   two kinds of links that may be used. First, an asset may possess a
   *parent*. This parental relationship is strict in the sense that an
   asset may not possess more than one parent.

   However, in addition to the parental relationship, it is possible
   to link the asset to an arbitrary number of additional database
   objects. These latter links have a key-value construction, meaning
   that one can access a given asset by reference to a given key, for
   example: "node.assets["response"]".

   Importantly, the same asset can have different keys for different
   objects; for example, it might be the "response" for one node, but
   the "stimulus" for another node. These latter relationships are
   instantiated with logic like the following:

      participant.assets["stimulus"] = my_asset

   creation_time

      the time at which the Network was created.

   delete_input()

      Deletes the input file(s) that make(s) up the asset.

   details

      a generic column for storing structured JSON data

   id

      a unique number for every entry. 1, 2, 3 and so on...

   property1

      a generic column that can be used to store experiment-specific
      details in String form.

   property2

      a generic column that can be used to store experiment-specific
      details in String form.

   property3

      a generic column that can be used to store experiment-specific
      details in String form.

   property4

      a generic column that can be used to store experiment-specific
      details in String form.

   property5

      a generic column that can be used to store experiment-specific
      details in String form.

   type

   vars

class psynet.asset.ExternalS3Asset(*args, **kwargs)

   Bases: "ExternalAsset"

   Represents an external asset that is stored in an Amazon Web
   Services S3 bucket.

   creation_time

      the time at which the Network was created.

   property default_storage

      The notional storage back-end for external web-hosted assets.

   delete_input()

      Deletes the input file(s) that make(s) up the asset.

   details

      a generic column for storing structured JSON data

   id

      a unique number for every entry. 1, 2, 3 and so on...

   property1

      a generic column that can be used to store experiment-specific
      details in String form.

   property2

      a generic column that can be used to store experiment-specific
      details in String form.

   property3

      a generic column that can be used to store experiment-specific
      details in String form.

   property4

      a generic column that can be used to store experiment-specific
      details in String form.

   property5

      a generic column that can be used to store experiment-specific
      details in String form.

   type

   vars

class psynet.asset.FastFunctionAsset(*args, **kwargs)

   Bases: "OnDemandAsset"

   Deprecated since version 11.7.0: Use "OnDemandAsset" instead.

   creation_time

      the time at which the Network was created.

   details

      a generic column for storing structured JSON data

   id

      a unique number for every entry. 1, 2, 3 and so on...

   property1

      a generic column that can be used to store experiment-specific
      details in String form.

   property2

      a generic column that can be used to store experiment-specific
      details in String form.

   property3

      a generic column that can be used to store experiment-specific
      details in String form.

   property4

      a generic column that can be used to store experiment-specific
      details in String form.

   property5

      a generic column that can be used to store experiment-specific
      details in String form.

   type

   vars

class psynet.asset.FileAsset(*args, **kwargs)

   Bases: "ManagedAsset"

   An asset made from an existing file or folder, such as a stimulus
   file declared in the timeline, a participant recording, or an
   analysis plot.

   File assets created while the experiment is running are included in
   "psynet export". File assets prepared before launch (for example
   stimuli attached to nodes in the timeline) are not exported,
   because they come from the experiment directory.

   Managed files are stored under a content-addressed
   "objects/sha256/<digest>" path. Local storage serves them via
   "/asset/<access_token>"; S3 storage uses a direct public object
   URL. Bytes that are already stored are not uploaded again.

   -[ Examples ]-

      import tempfile

      with tempfile.NamedTemporaryFile("w") as file:
          file.write(f"Your message here")
          asset = FileAsset(
              local_key="my_message",
              input_path=file.name,
              extension=".txt",
              parent=participant,
          )
          asset.deposit()

   creation_time

      the time at which the Network was created.

   details

      a generic column for storing structured JSON data

   id

      a unique number for every entry. 1, 2, 3 and so on...

   property1

      a generic column that can be used to store experiment-specific
      details in String form.

   property2

      a generic column that can be used to store experiment-specific
      details in String form.

   property3

      a generic column that can be used to store experiment-specific
      details in String form.

   property4

      a generic column that can be used to store experiment-specific
      details in String form.

   property5

      a generic column that can be used to store experiment-specific
      details in String form.

   type

   vars

class psynet.asset.FunctionAssetMixin(function, *, arguments=None, is_folder=False, description=None, data_type=None, extension=None, local_key=None, key_within_module=None, key_within_experiment=None, module_id=None, parent=None, personal=_PERSONAL_ARG_REMOVED, obfuscate=_OBFUSCATE_ARG_REMOVED)

   Bases: "object"

   This Mixin is used to define Asset classes that create their assets
   not from input files but from functions that are called with a
   specified set of arguments. It is not to be instantiated directly.

   Parameters:
      * **function** (*callable*) -- A function responsible for
        generating the asset. The function should receive an argument
        called "path" and create a file or a folder at that path. It
        can also receive additional arguments specified via the
        "arguments" parameter.

      * **arguments** (*dict*) -- An optional dictionary of arguments
        that should be passed to the function.

   computation_time_sec

      The time taken to generate the asset.

      Type:
         float

class psynet.asset.GeneratedAsset(*args, **kwargs)

   Bases: "FunctionAssetMixin", "ManagedAsset"

   An asset whose files are created by running a function. Generated
   assets declared in the timeline are generated at every launch, on
   the machine that prepares the deployment; generated assets created
   during the experiment are generated on the server. The upload is
   skipped when the output is identical to bytes already stored.

   Generated assets created during the experiment are included in
   "psynet export". Generated assets declared in the timeline are not,
   because the experiment code recreates them at every launch. For
   cheap files that should never be stored or exported, use
   "OnDemandAsset".

   creation_time

      the time at which the Network was created.

   details

      a generic column for storing structured JSON data

   id

      a unique number for every entry. 1, 2, 3 and so on...

   property1

      a generic column that can be used to store experiment-specific
      details in String form.

   property2

      a generic column that can be used to store experiment-specific
      details in String form.

   property3

      a generic column that can be used to store experiment-specific
      details in String form.

   property4

      a generic column that can be used to store experiment-specific
      details in String form.

   property5

      a generic column that can be used to store experiment-specific
      details in String form.

   type

   vars

class psynet.asset.LocalStorage(root=None)

   Bases: "AssetStorage"

   Stores assets in a local folder on the same computer that is
   running your Python code. This approach is suitable when you are
   running experiments on a single local machine (e.g. when doing
   fieldwork or laboratory-based data collection), and when you are
   deploying your experiments to your own remote web server via
   Docker. It is *not* appropriate if you deploy your experiments via
   Heroku, because Heroku deployments split the processing over
   multiple web servers, and these different web servers do not share
   the same file system.

   check_cache(host_path, is_folder)

      Checks whether the registry can find an asset cached at
      "host_path". The implementation is permitted to make
      optimizations for speed that may result in missed caches, i.e.
      returning "False" when the cache did actually exists. However,
      the implementation should only return "True" if it is certain
      that the asset cache exists.

      Returns:
         * "True" or "False".

   property root

      We defer the registration of the root until as late as possible
      to avoid circular imports when loading the experiment.

   serve(asset, subpath=None)

      Serve a deposited asset for an HTTP response.

      Subclasses should override this to return a Flask response.

   classmethod sftp_connection(ssh_host, ssh_user)

      Return an SFTP client for the host, reopening it if its SSH
      connection closed.

      The SSH connection that the SFTP client runs on can drop, or be
      closed elsewhere in the process, for example by Dallinger or by
      PsyNet's export code.

class psynet.asset.ManagedAsset(*args, **kwargs)

   Bases: "Asset"

   This is a parent class for assets that are actively 'managed' by
   PsyNet. Active managing means that PsyNet takes responsibility for
   storing the asset in its own storage repositories. This class is
   not generally instantiated directly, but is instead instantiated
   via its subclasses.

   Parameters:
      * **input_path** (*str*) -- Path to the file/folder from which
        the asset is to be created.

      * **local_key** (*str*) -- A string identifier for the asset,
        for example ""stimulus"". If provided, this string identifier
        should together with "parent" and "module_id" should uniquely
        identify that asset (i.e. no other asset should share that
        combination of properties).

      * **description** (*str*) -- An optional longer string that
        provides further documentation about the asset.

      * **is_folder** (*bool*) -- Whether the asset is a folder.

      * **data_type** (*str*) -- Experimental: the nature of the
        asset's data. Could be used to determine visualization methods
        etc.

      * **extension** (*str*) -- The file extension, if applicable.

      * **parent** (*object*) -- The object that 'owns' the asset, if
        applicable, for example a Participant or a Node.

      * **key_within_module** (*str*) -- An optional key that uniquely
        identifies the asset within a given module. If left
        unspecified, this will be automatically generated with
        reference to the "parent" and the "local_key" arguments.

      * **key_within_experiment** (*str*) -- A string that uniquely
        identifies the asset within a given experiment. If left
        unspecified, this will be automatically generated with
        reference to the "key_within_module" and the "module_id"
        arguments.

      * **module_id** (*str*) -- Identifies the module with which the
        asset should be associated. If left blank, PsyNet will attempt
        to infer the "module_id" from the "parent" parameter, if
        provided.

   sha256_contents

      SHA-256 digest of the asset bytes (or folder contents). Used as
      the immutable content identity.

      Type:
         str

   object_path

      Content-addressed storage path of the form
      "objects/sha256/<digest>".

      Type:
         str

   access_token

      Permanent unguessable token used for live browser access at
      "/asset/<token>".

      Type:
         str

   md5_contents

      Legacy MD5 digest retained for compatibility with older tooling.

      Type:
         str

   size_mb

      The size of the asset's file(s) (in MB).

      Type:
         float

   deposit_time_sec

      The time it took to deposit the asset.

      Type:
         float

   used_cache

      Whether identical bytes were already stored, so that the upload
      was skipped.

      Type:
         bool

   creation_time

      the time at which the Network was created.

   delete_input()

      Deletes the input file(s) that make(s) up the asset.

   details

      a generic column for storing structured JSON data

   get_sha256_contents()

      Return the SHA-256 digest of the asset's current input path.

   get_url()

      Return the browser URL for this managed asset.

      S3-backed assets use a direct public object URL. Locally stored
      assets use the permanent "/asset/<access_token>" route.

   id

      a unique number for every entry. 1, 2, 3 and so on...

   property1

      a generic column that can be used to store experiment-specific
      details in String form.

   property2

      a generic column that can be used to store experiment-specific
      details in String form.

   property3

      a generic column that can be used to store experiment-specific
      details in String form.

   property4

      a generic column that can be used to store experiment-specific
      details in String form.

   property5

      a generic column that can be used to store experiment-specific
      details in String form.

   type

   vars

class psynet.asset.NoStorage

   Bases: "AssetStorage"

   A 'null' storage back-end for assets that don't require any
   storage.

class psynet.asset.OnDemandAsset(*args, **kwargs)

   Bases: "FunctionAssetMixin", "ManagedAsset"

   An on-demand asset is generated when requested via its permanent
   access token URL ("/asset/<access_token>"). Bytes are not stored,
   so on-demand assets are never included in "psynet export".

   creation_time

      the time at which the Network was created.

   details

      a generic column for storing structured JSON data

   get_url()

      Return the browser URL for this managed asset.

      S3-backed assets use a direct public object URL. Locally stored
      assets use the permanent "/asset/<access_token>" route.

   id

      a unique number for every entry. 1, 2, 3 and so on...

   property1

      a generic column that can be used to store experiment-specific
      details in String form.

   property2

      a generic column that can be used to store experiment-specific
      details in String form.

   property3

      a generic column that can be used to store experiment-specific
      details in String form.

   property4

      a generic column that can be used to store experiment-specific
      details in String form.

   property5

      a generic column that can be used to store experiment-specific
      details in String form.

   type

   vars

class psynet.asset.S3Storage(s3_bucket, root, backend='boto3')

   Bases: "AssetStorage"

   A storage back-end that stores assets using Amazon Web Services' S3
   Storage system. This service is relatively inexpensive as long as
   your file collection does not number more than a few gigabytes. To
   use this service you will need to sign up for an Amazon Web
   Services account.

   You can use this storage back-end by setting the "asset_storage"
   property of your "Experiment" class in experiment.py, for example:

      import psynet.experiment
      from psynet.asset import S3Storage

      class Exp(psynet.experiment.Experiment):
          asset_storage = S3Storage("psynet-tests", "repp-tests")

   Parameters:
      * **s3_bucket** (*str*) -- The name of the S3 bucket to use.

      * **root** (*str*) -- The root directory within the bucket to
        use.

      * **backend** (*str*) -- The backend to use for transferring
        files to S3. Can be either "boto3" or "awscli". "awscli"
        relies on aws client being installed. It is faster than
        "boto3" (especially for uploading folders) but requires more
        dependencies which are not supported on Heroku. The default is
        "boto3".

   check_cache(host_path, is_folder, use_cache=None)

      Checks whether a file or folder is present in the remote bucket.
      Uses caching where appropriate for efficiency.

   move_file(s3_key, new_s3_key)

      Move a file from one location to another within the S3 bucket.

      Parameters:
         * **s3_key** ("str") -- The current path of the file in the
           S3 bucket.

         * **new_s3_key** ("str") -- The new path where the file
           should be moved.

   serve(asset, subpath=None)

      Redirect to the public S3 object URL.

      Managed S3 assets are linked directly in the browser; PsyNet
      does not proxy object bytes. This method remains for
      "/asset/<token>" requests that still resolve to an S3-backed
      asset (for example older tokens).

class psynet.asset.WebStorage

   Bases: "AssetStorage"

   The notional storage back-end for external web-hosted assets.

psynet.asset.asset(source, *, on_demand=False, arguments=None, local_key=None, key_within_module=None, key_within_experiment=None, description=None, is_folder=False, data_type=None, extension=None, parent=None, module_id=None, personal=_PERSONAL_ARG_REMOVED, cache=_CACHE_ARG_UNSET)

   Create an asset.

   Most users will find this the easiest way to create assets.
   Advanced users can also create assets via the constructor functions
   for each asset type: - "ExternalAsset" - "FileAsset" -
   "GeneratedAsset" - "OnDemandAsset"

   Whether an asset is included in "psynet export" follows from when
   it was made: file and generated assets created while the experiment
   is running are exported, and assets prepared before launch are not.
   On-demand and external assets are never exported.

   Parameters:
      * **source** (*str**, **Path**, or **callable*) -- The source of
        the asset. If a string or Path, it will be treated as a local
        file or URL. If a callable, it will be treated as a function
        that generates the asset.

      * **on_demand** (*bool**, **default=False*) -- Whether to
        generate a function asset on demand, each time it is
        requested, instead of once when it is created.

      * **arguments** (*dict**, **optional*) -- Arguments to pass to
        the function if source is a callable.

      * **local_key** (*str*) -- A string identifier for the asset,
        for example ""stimulus"". If provided, this string identifier
        should together with "parent" and "module_id" uniquely
        identify that asset (i.e. no other asset should share that
        combination of properties).

      * **key_within_module** (*str*) -- A string that uniquely
        identifies the asset within a given module. If left
        unspecified, this will be automatically generated with
        reference to the "parent" and the "local_key" arguments.

      * **key_within_experiment** (*str*) -- A string that uniquely
        identifies the asset within a given experiment. If left
        unspecified, this will be automatically generated with
        reference to the "key_within_module" and the "module_id"
        arguments.

      * **description** (*str*) -- An optional longer string that
        provides further documentation about the asset.

      * **is_folder** (*bool*) -- Whether the asset is a folder.

      * **data_type** (*str*) -- Experimental: the nature of the
        asset's data. Could be used to determine visualization methods
        etc.

      * **extension** (*str*) -- The file extension, if applicable.

      * **parent** (*object*) -- The object that 'owns' the asset, if
        applicable, for example a Participant or a Node.

      * **module_id** (*str*) -- The module within which the asset is
        located.

      * **cache** (*bool*) -- Deprecated and ignored. All managed
        assets skip uploading bytes that are already stored.

   Returns:
      The created asset. Depending on the input arguments, this could
      be: - ExternalAsset: For assets hosted externally at a URL -
      FileAsset: For assets made from a local file or folder -
      GeneratedAsset: For assets generated by a function -
      OnDemandAsset: For assets generated by a function on demand

   Return type:
      Asset

psynet.asset.list_files_in_s3_bucket(bucket_name, prefix='', recursive=True, sort_by_date=False, params=None)

   Lists files in an S3 bucket.

   Parameters:
      * **bucket_name** ("str") -- Bucket to list files within.

      * **prefix** ("str") -- Only lists files whose keys begin with
        this string.

      * **recursive** ("bool") -- Whether to list files recursively.

      * **sort_by_date** ("bool") -- Whether to sort files by
        modification date.

      * **params** ("Optional"["dict"]) -- Additional parameters to
        pass to the S3 client.

   Returns:
      * *A generator that yields keys.*
