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.0.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.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: parameter_toolkit-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 5ec6e6a216dd3ea7953905afb7c2bcb40daba39a1a11a05c47dabbe28767ffbf
MD5 a323797228dcadf653c826e94776e222
BLAKE2b-256 154e8676c1f90be5c410c2b582e08f189056d69593ea9684d8250a46f07cd1e7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for parameter_toolkit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3194309e9e4b62086812b46153578ca64580613759aa68233c943d75e481c0d3
MD5 ac2c2f1c8aaae4f82a9e63ec982ba924
BLAKE2b-256 2a36d68af2e5c777bcfe0255e95e676388498b8aa9efee3ee4e9e3fa496ecd85

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