Skip to main content

ProxyPatternPool

Generic Proxy and Pool classes for Python.

Status Tests Coverage Issues Python Version Badges License

This module provides two classes:

  • Proxy implements the proxy pattern, i.e. all calls to methods on the proxy are forwarded to an internally wrapped object. This allows to solve the classic chicken-and-egg importation and initialization possibly circular-dependency issue with Python modules:

    # File "database.py"
    db = Proxy()
    
    def init_app(config):
        db.set_obj(initialization from config)
    
    # File "app.py"
    import database
    from database import db  # db is a proxy to nothing
    …
    # delayed initialization
    database.init_app(config)
    
    # db is now a proxy to the initialized object
    

    When an internal pool is used, method _ret_obj must be called to return the object to the pool when done with it.

  • Pool implements a full-featured thread-safe pool of things which can be used to store expensive-to-create objects such as database connections, to be shared between threads for instance. The above proxy object creates a pool automatically depending on its parameters.

    This generic pool class can be used independently of the Proxy class.

    It provides numerous hooks to provide callbacks for creation, deletion, stats, tracing, health check… which makes it ideal to manage any kind of expensive resources within a process.

    import ProxyPatternPool as ppp
    
    # start a pool with 2 resources created by "fun"
    pool = ppp.Pool(
        fun = lambda n: f"expensive object {n}",
        min_size=2, max_size=2, timeout=0.5,
    )
    
    # get resources
    a = pool.get(); b = pool.get()  # max_size reached
    try:
        c = pool.get()  # will timeout after 0.5 seconds
        assert False
    except ppp.TimeOut:
        pass
    
    pool.ret(a); pool.ret(b);  # return resources
    
    pool.shutdown()
    del pool
    

License

This code is Public Domain.

All software has bug, this is software, hence… Beware that you may lose your hairs or your friends because of it. If you like it, feel free to send a postcard to the author.

Versions

Sources, documentation and issues are hosted on GitHub. Install package from PyPI. See version details.

Metadata

Release files for ProxyPatternPool 11.7

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

Source distribution (sdist)

Source distribution for ProxyPatternPool 11.7
File Size Uploaded Provenance Actions
proxypatternpool-11.7.tar.gz 13.2 kB Without provenance Details for proxypatternpool-11.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ProxyPatternPool 11.7
File Interpreter ABI Platform Actions
proxypatternpool-11.7-py3-none-any.whl Python 3 none any Details for proxypatternpool-11.7-py3-none-any.whl

Total release size: 24.9 kB

Release files / proxypatternpool-11.7.tar.gz

Download URL proxypatternpool-11.7.tar.gz
Size 13.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b631eb4f76d89eb5c38bb688ee76aa3bdfb90b66a37255f21a601a0930a053ed
BLAKE2b-256 checksum
How to use checksums
c86287ac5f0878a2035fd8bc3d62acaef486cf23a84631d30218ef1f7a703ce2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / proxypatternpool-11.7-py3-none-any.whl

Download URL proxypatternpool-11.7-py3-none-any.whl
Size 11.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
687962bd4c1c2f8bb82ab12677d9fdcc147f96f7043556962069fe7c4c6ca23f
BLAKE2b-256 checksum
How to use checksums
f9c0a108549e2aada8152f588bd9e80611ca20719729f93f3e2b7dd3461533a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Security for ProxyPatternPool 11.7

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

11.7 This release

2 release files 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