Skip to main content

Qtils - pronounces as `cuteels` - is a syntactic sugar library to make sweet Python coding even sweeter.

Project description

https://qtils.readthedocs.io/en/latest/_images/qtils-logo.png
GitHub tag (latest SemVer) Travis CI build status Code Coverage Documentation Status PyPI GitHub issues

Overview

Qtils - pronounces as cuteels - is a syntactic sugar library to make sweet Python coding even sweeter.

Dedication

This library is dedicated to Pál Hubai, Surfy, my programming Master who spent countless hours answering my questions, providing code examples, and guiding me towards the right approach when I was learning programming as a child. Thank you!

Documentation

Features

Installation

Qtils is available in PyPI:

$ pip install qtils

Examples

Attribute dictionary

>>> from qtils import *

>>> d = qdict()
>>> d.hello = "world"
>>> d.hello
'world'
>>> d.answer = 42
>>> d['answer']
42

Objects with self-formatting capability

>>> class MyObject(PrettyObject):
...     __pretty_fields__ = [
...         'hello',
...         'answer',
...     ]
...     def __init__(self, hello, answer):
...         self.hello = hello
...         self.answer = answer
>>> obj = MyObject('world', 42)
>>> print(obj)
<__main__.MyObject object at ... hello='world', answer=42>

Cached property

>>> class Foo(object):
...     @cachedproperty
...     def bar(self):
...         # doing some super computation-intensive thing here
...         print('getter called')
...         return "hello world"
...
>>> obj = Foo()
>>> obj.bar     # first call, getter is called
getter called
'hello world'
>>> obj.bar     # second call, getter is not called
'hello world'
>>> del obj.bar # removing cached value
>>> obj.bar     # getter is called again
getter called
'hello world'

Formatting and parsing file sizes

>>> print(DataSize(123000))
123 k
>>> DataSize('1.45 megabytes')
1450000
>>> DataSize('1T').format(unit="k", number_format="{:,.0f} {}")
'1,000,000,000 k'

Adding a class-private logger

>>> @logged
... class LoggedFoo():
...     def __init__(self):
...         self.__logger.info("Hello World from Foo!")
...

See more examples and usage in examples and tutorials.

Contribution

Pull requests are always welcome.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qtils-0.9.4.tar.gz (22.9 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page