Skip to main content
Build status

Cask is Injector-enabled, Python application microframework modelled after Flask.

It’s purpose is to make the amount of boilerplate you need to write when developing your application smaller. Here’s a simple example:

>>> from cask import Cask
>>> from injector import inject
>>>
>>> def configure(binder):
...     binder.bind(str, to='ABC')
...
>>> @Cask.run_main(modules=[configure])
... @inject(s=str)
... def main(s):
...     print(s)
...
ABC

Cask.run_main (it works both as class and instance method, see below) does the if __name__ == '__main__' check for you. So this

>>> app = Cask()
>>> @app.run_main
... def main():
...     print(111)
...
111

is shorter version of

>>> app = Cask()
>>> @app.main
... def main():
...     print(222)
...
>>> if __name__ == '__main__':
...     app.run()
...
222

Construction

Cask constructor and Cask.run_main class method accept the following optional keyword arguments:

  • modules - iterable of Injector modules, defaults to empty sequence

  • injector- instance of Injector to configure and use, by default new instance will be created for you

Hooks

Cask instance provides the following decorators allowing you to register hooks (note that you can inject into registered functions):

  • Cask.before_main - should expect no parameters, if non-None value is returned application execution main function won’t be executed

  • Cask.after_main - should expect single result parameter and return processed result (modified or not)

  • Cask.exception_handler(ExceptionCLass) - will handle exception raised during the application execution, should expect single argument called e and containing exception value:

    >>> app = Cask()
    >>> @app.exception_handler(Exception)
    ... def handle(e):
    ...     print('got exception %s' % (e,))
    ...
    >>> @app.run_main
    ... def main():
    ...     raise Exception(123)
    ...
    got exception 123
  • Cask.main - main function should expect no arguments and may return something

You can, of course, register more than one callable for hooks other than main.

Execution

This is what happens when you run Cask-based application:

  1. Injector is configured using provided modules

  2. before_main hooks are called

  3. If before_main hooks didn’t return value different than None, main hook is executed

  4. after_main hooks are called

Metadata

Release files for cask 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cask 0.1.1
File Size Uploaded Provenance Actions
cask-0.1.1.tar.gz 3.6 kB Without provenance Details for cask-0.1.1.tar.gz

Release files / cask-0.1.1.tar.gz

Download URL cask-0.1.1.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
4c8bff7957f5393912edf85bb2dcb868baa4e5064be379835e3ad45dd9b26b26
BLAKE2b-256 checksum
How to use checksums
ba963c431a06ee27017fd440715e7e2b706a091caf0888f2a1cde5b1d08a40e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for cask 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page