Skip to main content

python-options

Make python class with option base on property. Using build option for client like kafka, command option like ffmpeg.

Support: python 3.6+

Feature:

  • Build options (config) easily.
  • Clone option (changing not effect with other config which initial from single class)
  • (Optional) Filter value on set.
  • (Optional) Auto fill default value if delete old value.

Example:

from typing import Any, Type
from pyopt import Options, UnsetOption, option


def filter_type(_type: Type):
    def _filter_wrapper(instance: Any):
        if not isinstance(instance, _type):
            raise TypeError(f"Instance must be `{_type.__name__}`")
        return instance
    return _filter_wrapper


class Config(Options):
    server = option("url", filter_type(str), doc="URL of server host.")

if __name__ == '__main__':
    conf = Config()
    try:
        conf.server = 1  # raise TypeError
    except TypeError as e:
        print(f"ERROR: {e}")

    try:
        print(conf.server)
    except UnsetOption as e:
        print(f"Unset: {e}")

    conf.server = "127.0.0.1:9090"
    print(conf.__repr__())
    print(conf.build())


>>> config = Config()

>>> config.server = 1
TypeError: Instance must be `str`

>>> conf.server
The option `url` of Config hasn't been set.

>>> config.server = "127.0.0.1:9090"
>>> print(conf)
Config:
    - server         | "url" = "127.0.0.1:9090"                    | Doc: URL of server host.

>>> print(conf.build())
{'url': '127.0.0.1:9090'}

Info

Author = "Tin Dang"
Copyright = "Copyright (C) 2020 DPS"
Version = "1.0"
Doc = "Options base on property which help build dict name=value with value filter."

Metadata

Release files for python-options 1.0.0.post4

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

Source distribution (sdist)

Source distribution for python-options 1.0.0.post4
File Size Uploaded Provenance Actions
python-options-1.0.0.post4.tar.gz 5.4 kB Without provenance Details for python-options-1.0.0.post4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for python-options 1.0.0.post4
File Interpreter ABI Platform Actions
python_options-1.0.0.post4-py3-none-any.whl Python 3 none any Details for python_options-1.0.0.post4-py3-none-any.whl

Total release size: 11.7 kB

Release files / python-options-1.0.0.post4.tar.gz

Download URL python-options-1.0.0.post4.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
3df5b04764e460eedff901d784ba09b35bb449c46a24c8e5c8ab918b63ef1ad4
BLAKE2b-256 checksum
How to use checksums
e51b3b153db871728e817a996a013838047ad529e03b0a46f4594fa81f211348
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.5

Release files / python_options-1.0.0.post4-py3-none-any.whl

Download URL python_options-1.0.0.post4-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c0d567527a09c487765558b6bb037d1b809df29c3d93ee7b937af4f271daa8a8
BLAKE2b-256 checksum
How to use checksums
4178a46aa8be44e8822e036ba1884dda72a499099d150fc645392a5288d2ad53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.5

Security for python-options 1.0.0.post4

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.

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