core ==== .. py:module:: core .. autoapi-nested-parse:: ViUR-core Copyright © 2026 Mausbrand Informationssysteme GmbH https://core.docs.viur.dev Licensed under the MIT license. See LICENSE for more information. Submodules ---------- .. toctree:: :maxdepth: 1 /viur/core/bones/index /viur/core/cache/index /viur/core/config/index /viur/core/current/index /viur/core/db/index /viur/core/decorators/index /viur/core/email/index /viur/core/errors/index /viur/core/i18n/index /viur/core/languages/index /viur/core/logging/index /viur/core/module/index /viur/core/modules/index /viur/core/pagination/index /viur/core/prototypes/index /viur/core/ratelimit/index /viur/core/render/index /viur/core/request/index /viur/core/secret/index /viur/core/securityheaders/index /viur/core/securitykey/index /viur/core/session/index /viur/core/skeleton/index /viur/core/tasks/index /viur/core/utils/index /viur/core/version/index Classes ------- .. autoapisummary:: core.DeleteEntitiesIter core.QueryIter Functions --------- .. autoapisummary:: core.callDeferred core.CallDeferred core.PeriodicTask core.retry_n_times core.StartupTask core.setDefaultLanguage core.setDefaultDomainLanguage core.setup Package Contents ---------------- .. py:function:: callDeferred(func) Deprecated version of CallDeferred .. py:function:: CallDeferred(func) This is a decorator, which always calls the wrapped method deferred. The call will be packed and queued into a Cloud Tasks queue. The Task Queue calls the TaskHandler which executed the wrapped function with the originally arguments in a different request. In addition to the arguments for the wrapped methods you can set these: _queue: Specify the queue in which the task should be pushed. If no value is given, the queue name set in `conf.tasks_default_queues` will be used. If the config does not have a value for this task, "default" is used as the default. The queue must exist (use the queue.yaml). _countdown: Specify a time in seconds after which the task should be called. This time is relative to the moment where the wrapped method has been called. _eta: Instead of a relative _countdown value you can specify a `datetime` when the task is scheduled to be attempted or retried. _name: Specify a custom name for the cloud task. Must be unique and can contain only letters ([A-Za-z]), numbers ([0-9]), hyphens (-), colons (:), or periods (.). _target_version: Specify a version on which to run this task. By default, a task will be run on the same version where the wrapped method has been called. _call_deferred: Calls the @CallDeferred decorated method directly. This is for example necessary, to call a super method which is decorated with @CallDeferred. .. code-block:: python # Example for use of the _call_deferred-parameter class A(Module): @CallDeferred def task(self): ... class B(A): @CallDeferred def task(self): super().task(_call_deferred=False) # avoid secondary deferred call ... See also: https://cloud.google.com/python/docs/reference/cloudtasks/latest/google.cloud.tasks_v2.types.Task https://cloud.google.com/python/docs/reference/cloudtasks/latest/google.cloud.tasks_v2.types.CreateTaskRequest .. py:class:: DeleteEntitiesIter Bases: :py:obj:`QueryIter` Simple Query-Iter to delete all entities encountered. ..Warning: When iterating over skeletons, make sure that the query was created using `Skeleton().all()`. This way the `Skeleton.delete()` method can be used and the appropriate post-processing can be done. .. py:method:: handleEntry(entry, customData) :classmethod: Overridable hook to process one entry. "entry" will be either an db.Entity or an SkeletonInstance (if that query has been created by skel.all()) Warning: If your query has an sortOrder other than __key__ and you modify that property here it is possible to encounter that object later one *again* (as it may jump behind the current cursor). .. py:function:: PeriodicTask(interval = 0, cronName = 'default') Decorator to call a function periodically during cron job execution. Interval defines a lower bound for the call-frequency for the given task, specified as a timedelta. The true interval of how often cron jobs are being executed is defined in the project's cron.yaml file. This defaults to 4 hours (see https://github.com/viur-framework/viur-base/blob/main/deploy/cron.yaml). In case the interval defined here is lower than 4 hours, the task will be fired once every 4 hours anyway. :param interval: Call at most the given timedelta. .. py:class:: QueryIter Bases: :py:obj:`object` BaseClass to run a database Query and process each entry matched. This will run each step deferred, so it is possible to process an arbitrary number of entries without being limited by time or memory. To use this class create a subclass, override the classmethods handleEntry and handleFinish and then call startIterOnQuery with an instance of a database Query (and possible some custom data to pass along) .. py:attribute:: queueName :value: 'default' .. py:method:: startIterOnQuery(query, customData = None) :classmethod: Starts iterating the given query on this class. Will return immediately, the first batch will already run deferred. Warning: Any custom data *must* be json-serializable and *must* be passed in customData. You cannot store any data on this class as each chunk may run on a different instance! .. py:method:: _requeueStep(qryDict) :classmethod: Internal use only. Pushes a new step defined in qryDict to either the taskqueue or append it to the current request if we are on the local development server. .. py:method:: _qryStep(qryDict) :classmethod: Internal use only. Processes one block of five entries from the query defined in qryDict and reschedules the next block. .. py:method:: handleEntry(entry, customData) :classmethod: Overridable hook to process one entry. "entry" will be either an db.Entity or an SkeletonInstance (if that query has been created by skel.all()) Warning: If your query has an sortOrder other than __key__ and you modify that property here it is possible to encounter that object later one *again* (as it may jump behind the current cursor). .. py:method:: handleFinish(totalCount, customData) :classmethod: Overridable hook that indicates the current run has been finished. .. py:method:: handleError(entry, customData, exception) :classmethod: Handle a error occurred in handleEntry. If this function returns True, the queryIter continues, otherwise it breaks and prints the current cursor. .. py:function:: retry_n_times(retries, email_recipients = None, tpl = None) Wrapper for deferred tasks to limit the amount of retries :param retries: Number of maximum allowed retries :param email_recipients: Email addresses to which a info should be sent when the retry limit is reached. :param tpl: Instead of the standard text, a custom template can be used. The name of an email template must be specified. .. py:function:: StartupTask(fn) Functions decorated with this are called shortly at instance startup. It's *not* guaranteed that they actually run on the instance that just started up! Wrapped functions must not take any arguments. .. py:function:: setDefaultLanguage(lang) Sets the default language used by ViUR to *lang*. :param lang: Name of the language module to use by default. .. py:function:: setDefaultDomainLanguage(domain, lang) If conf.i18n.language_method is set to "domain", this function allows setting the map of which domain should use which language. :param domain: The domain for which the language should be set :param lang: The language to use (in ISO2 format, e.g. "DE") .. py:function:: setup(modules, render = None, default = 'html') Define whats going to be served by this instance. :param modules: Usually the module provided as *modules* directory within the application. :param render: Usually the module *viur.core.renders*, or a dictionary renderName => renderClass. :param default: Name of the renderer, which will form the root of the application. This will be the renderer, which wont get a prefix, usually html. (=> /user instead of /html/user)