Skip to main content

1 decore

PyPI-Status PyPI-Versions Build-Status Codecov LICENCE

A small pure-python package for utility decorators.

from decore import lazy_property

@lazy_property
def paramless_big_calc():
  sub_res = [big_func(const) for const in array_of_constants]
  return sum(sub_res)

1.1 Installation

Install decore with:

pip install decore

1.2 Decorators

1.2.1 lazy_property

The lazy_property decorator is meant to decorate functions that compute some constant value or property that you only want to compute once. The first call to the decorated function will run it and save the value (in memory) before returning it; subsequent calls will get this value without triggering the calculation.

You can think about it like a functools.lru_cache(maxsize=1) for functions with no parameters.

from decore import lazy_property

@lazy_property
def paramless_big_calc():
  """I take a lot of time!"""
  sub_res = [big_func(const) for const in array_of_constants]
  return sum(sub_res)

1.2.2 threadsafe_generator

The threadsafe_generator decorator makes generators threadsafe. This means multiple threads can be given references to the decorated generator and it is guaranteed that each item in the stream will be yielded (i.e. returned) to only a single thread.

from decore import threadsafe_generator

@threadsafe_generator
def user_documents(day):
  """I yield some MongoDB documents!"""
  client = get_mongodb_client(some_params)
  dt_obj = translate_day_to_dt(day)
  user_document_cursor = client.some_mongodb_query(dt_obj, SOME_CONST)
  while True:
    yield user_document_cursor.__next__()

1.3 Contributing

Package author and current maintainer is Shay Palachy (shay.palachy@gmail.com); You are more than welcome to approach him for help. Contributions are very welcomed.

1.3.1 Installing for development

Clone:

git clone git@github.com:shaypal5/decore.git

Install in development mode with test dependencies:

cd decore
pip install -e ".[test]"

1.3.2 Running the tests

To run the tests, use:

python -m pytest --cov=decore

1.3.3 Adding documentation

This project is documented using the numpy docstring conventions, which were chosen as they are perhaps the most widely-spread conventions that are both supported by common tools such as Sphinx and result in human-readable docstrings (in my personal opinion, of course). When documenting code you add to this project, please follow these conventions.

1.4 Credits

Created by Shay Palachy (shay.palachy@gmail.com).

Metadata

Release files for decore 0.0.4

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

Source distribution (sdist)

Source distribution for decore 0.0.4
File Size Uploaded
decore-0.0.4.tar.gz 6.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for decore 0.0.4
File Interpreter ABI Platform
decore-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 12.9 kB

Release files / decore-0.0.4.tar.gz

Download URL decore-0.0.4.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
2b5885efa421cafac4b35faea042b213e8b0156f38d5d761c8957891bc0bb8f9
BLAKE2b-256 checksum
How to use checksums
646e8bd1a9ff65f6529bdf9cc7908fcb5b58320fe1d313a96500055137e2a4f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Release files / decore-0.0.4-py3-none-any.whl

Download URL decore-0.0.4-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7c7e41ff677a2e28de4e34c21257bcb895ea82318237ec464d52b406f1eb3bc1
BLAKE2b-256 checksum
How to use checksums
b40db612991320221e3b90f3572cc613f944ab12cf387acb8445ccc3c7859b8d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.2

2 release files

0.0.1

1 release file

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