Skip to main content

A python library to interact with inspects Parameters objects.

Project description

Parameter-Toolkit

A small python library to interact with and convert parameters.

Working on a different project where I want to receive optional commands in a human readable manner I dug a bit deeper into the world of inspect, functools and astlib and discovered there is no low-level way to interact with python-signatures.

This library meant to overcome this bt providing Utitlites to access Parameters of Signatures in a more primitive manner.

Features:

Parameter Tools:

  • Get all Parameter objects from a func with inspect shorthand (Either as list or generator).
  • Convert function parameters to a dict of python BuiltIns.

LiteralParameter Tools:

  • Extract string of literal paramaters to convert them with ast.literalEval into usable `args' and 'kwargs'!

    • All types supported by astlib are extractable/slicable
    • Supports nested containers
  • Map a literal parameteres directly to a function and get apartial` object. (WIP)

  • NO external dependencies

Get functions parameter info:

    def helloWorld(name_to_greet:str="World!"):
        return f"Hello {name_to_greet}"

    func_parameters_info = getFuncParameterAsDict(helloWord)
    for p in func_parameters_info:
        print(p)
    '''
    {"name":"name_to_greet", "type":"str", "default": "World!", "kind"}    
    '''

Convert a single parameter to dict:

    parameter_info = parameterToDict(myExtractedParemeter)
    print(parameter_info)

    '''
    {"name":"name_to_greet", "type":"str", "default": "World!", "kind"}    
    '''

Convert a stringified parameters to positional and keyword args:

    myParameterString = '"Please write me in Upper\\"s", True, repeat=5", data=[4,2,1,[6,2],8] ...'
    extracted_parameters = LiteralParameterExtraxtor(myParameterString).extractStringParameters()

Known Bugs

  • No more bugs known (yet!)

Happy Hacking!

Get it on Codeberg

Licensing

All of the provided code as well as readme and other releated files to the library are published under: GPLv3

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

parameter_toolkit-0.1.1.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

parameter_toolkit-0.1.1-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file parameter_toolkit-0.1.1.tar.gz.

File metadata

  • Download URL: parameter_toolkit-0.1.1.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for parameter_toolkit-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ada922ce90cf6e46e5a44a35e799825888752e4d67b5b75b7a7a608e4b252140
MD5 1c6f5f7b07ccab85412fe0e6fc5653e0
BLAKE2b-256 6d9d2f7f1532fc83353433ce3c9a6f3327bda2a9412c12b06b2831bcb3e034db

See more details on using hashes here.

File details

Details for the file parameter_toolkit-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for parameter_toolkit-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5d3e9d5df72e2d825c010f996d50ed68559779d4aac441c1f0ba500e8f4f637a
MD5 3cc55da78e4f7b26d8997925a069976b
BLAKE2b-256 d8016e5cae16139e59e29d6324f5cab2e5bd3085bf1c9c10ffbc02a5b75aac16

See more details on using hashes here.

Supported by

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