argset


Nameargset JSON
Version 0.1.1.post1 PyPI version JSON
download
home_pageNone
SummarySimple callable argument inspection & filtering
upload_time2025-10-28 12:42:51
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords arguments callable inspect keyword arguments signature
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            |repostatus| |ci-status| |coverage| |pyversions| |license|

.. |repostatus| image:: https://www.repostatus.org/badges/latest/unsupported.svg
    :target: https://www.repostatus.org/#unsupported
    :alt: Project Status: Unsupported – The project has reached a stable,
          usable state but the author(s) have ceased all work on it. A new
          maintainer may be desired.

.. |ci-status| image:: https://github.com/jwodder/argset/actions/workflows/test.yml/badge.svg
    :target: https://github.com/jwodder/argset/actions/workflows/test.yml
    :alt: CI Status

.. |coverage| image:: https://codecov.io/gh/jwodder/argset/branch/master/graph/badge.svg
    :target: https://codecov.io/gh/jwodder/argset

.. |pyversions| image:: https://img.shields.io/pypi/pyversions/argset.svg
    :target: https://pypi.org/project/argset/

.. |license| image:: https://img.shields.io/github/license/jwodder/argset.svg
    :target: https://opensource.org/licenses/MIT
    :alt: MIT License

`GitHub <https://github.com/jwodder/argset>`_
| `PyPI <https://pypi.org/project/argset/>`_
| `Issues <https://github.com/jwodder/argset/issues>`_
| `Changelog <https://github.com/jwodder/argset/blob/master/CHANGELOG.md>`_

``argset`` provides a simple interface for determining whether a callable takes
an argument with a given name, filtering a ``dict`` of potential arguments down
to just those that a callable accepts, and determining any required arguments
that are missing from a ``dict`` of potential arguments.

Installation
============
``argset`` requires Python 3.8 or higher.  Just use `pip
<https://pip.pypa.io>`_ for Python 3 (You have pip, right?) to install
``argset`` and its dependencies::

    python3 -m pip install argset


Examples
========

Inspecting a function's arguments::

    >>> from argset import argset
    >>> def my_func(foo, bar):
    ...     print(f"foo={foo!r}")
    ...     print(f"bar={bar!r}")
    ...
    >>> a = argset(my_func)
    >>> "foo" in a
    True
    >>> "quux" in a
    False

Filtering a set of arguments to just those accepted by the function::

    >>> a.select({"foo": 42, "bar": 23, "quux": 17})
    {'foo': 42, 'bar': 23}
    >>> my_func(**a.select({"foo": 42, "bar": 23, "quux": 17}))
    foo=42
    bar=23

Same as above, but now the function takes ``**kwargs``::

    >>> from argset import argset
    >>> def my_func2(foo, **kwargs):
    ...     print(f"foo={foo!r}")
    ...     for k, v in kwargs.items():
    ...          print(f"{k}={v!r}")
    ...
    >>> a2 = argset(my_func2)
    >>> "foo" in a2
    True
    >>> "quux" in a2
    True
    >>> a2.select({"foo": 42, "bar": 23, "quux": 17})
    {'foo': 42, 'bar': 23, 'quux': 17}
    >>> my_func2(**a2.select({"foo": 42, "bar": 23, "quux": 17}))
    foo=42
    bar=23
    quux=17


API
===

.. code:: python

    argset(func: Callable) -> ArgSet

Inspects a callable and returns a summary of its arguments as an ``ArgSet``

.. code:: python

    class ArgSet

A representation of the arguments taken by a callable.  It has the following
attributes & properties:

``required_positional_only: int``
    The number of arguments that are positional-only and do not have default
    values

``optional_positional_only: int``
    The number of arguments that are positional-only and have a default value

``positional_only: int``
    The total number of positional-only arguments

``required_args: frozenset[str]``
    The names of all positional-or-keyword or keyword-only arguments that do
    not have default values

``optional_args: frozenset[str]``
    The names of all positional-or-keyword or keyword-only arguments that have
    default values

``argnames: frozenset[str]``
    The names of all positional-or-keyword or keyword-only arguments

``takes_args: bool``
    Whether the callable has an argument of the form ``*args``

``takes_kwargs: bool``
    Whether the callable has an argument of the form ``**kwargs``

``ArgSet`` objects support the ``in`` operator; an expression of the form
``argname in a`` returns ``True`` iff ``argname`` is in ``a.argnames`` or
``a.takes_kwargs`` is ``True``.

``ArgSet`` objects have the following methods:

.. code:: python

    ArgSet.select(kwargs: Dict[str, Any]) -> Dict[str, Any]

Returns all items in ``kwargs`` where the key is the name of a
positional-or-keyword or keyword-only argument accepted by the callable.  If
``takes_kwargs`` is ``True``, the return value is a copy of ``kwargs``.

.. code:: python

    ArgSet.missing(kwargs: Dict[str, Any]) -> FrozenSet[str]

Returns all keys in ``required_args`` that do not appear in ``kwargs``

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "argset",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "arguments, callable, inspect, keyword arguments, signature",
    "author": null,
    "author_email": "John Thorvald Wodder II <argset@varonathe.org>",
    "download_url": "https://files.pythonhosted.org/packages/05/2a/2de8543f155c71d66d943f7c924ac8135503414c1b3fb79350763cd8b3b9/argset-0.1.1.post1.tar.gz",
    "platform": null,
    "description": "|repostatus| |ci-status| |coverage| |pyversions| |license|\n\n.. |repostatus| image:: https://www.repostatus.org/badges/latest/unsupported.svg\n    :target: https://www.repostatus.org/#unsupported\n    :alt: Project Status: Unsupported \u2013 The project has reached a stable,\n          usable state but the author(s) have ceased all work on it. A new\n          maintainer may be desired.\n\n.. |ci-status| image:: https://github.com/jwodder/argset/actions/workflows/test.yml/badge.svg\n    :target: https://github.com/jwodder/argset/actions/workflows/test.yml\n    :alt: CI Status\n\n.. |coverage| image:: https://codecov.io/gh/jwodder/argset/branch/master/graph/badge.svg\n    :target: https://codecov.io/gh/jwodder/argset\n\n.. |pyversions| image:: https://img.shields.io/pypi/pyversions/argset.svg\n    :target: https://pypi.org/project/argset/\n\n.. |license| image:: https://img.shields.io/github/license/jwodder/argset.svg\n    :target: https://opensource.org/licenses/MIT\n    :alt: MIT License\n\n`GitHub <https://github.com/jwodder/argset>`_\n| `PyPI <https://pypi.org/project/argset/>`_\n| `Issues <https://github.com/jwodder/argset/issues>`_\n| `Changelog <https://github.com/jwodder/argset/blob/master/CHANGELOG.md>`_\n\n``argset`` provides a simple interface for determining whether a callable takes\nan argument with a given name, filtering a ``dict`` of potential arguments down\nto just those that a callable accepts, and determining any required arguments\nthat are missing from a ``dict`` of potential arguments.\n\nInstallation\n============\n``argset`` requires Python 3.8 or higher.  Just use `pip\n<https://pip.pypa.io>`_ for Python 3 (You have pip, right?) to install\n``argset`` and its dependencies::\n\n    python3 -m pip install argset\n\n\nExamples\n========\n\nInspecting a function's arguments::\n\n    >>> from argset import argset\n    >>> def my_func(foo, bar):\n    ...     print(f\"foo={foo!r}\")\n    ...     print(f\"bar={bar!r}\")\n    ...\n    >>> a = argset(my_func)\n    >>> \"foo\" in a\n    True\n    >>> \"quux\" in a\n    False\n\nFiltering a set of arguments to just those accepted by the function::\n\n    >>> a.select({\"foo\": 42, \"bar\": 23, \"quux\": 17})\n    {'foo': 42, 'bar': 23}\n    >>> my_func(**a.select({\"foo\": 42, \"bar\": 23, \"quux\": 17}))\n    foo=42\n    bar=23\n\nSame as above, but now the function takes ``**kwargs``::\n\n    >>> from argset import argset\n    >>> def my_func2(foo, **kwargs):\n    ...     print(f\"foo={foo!r}\")\n    ...     for k, v in kwargs.items():\n    ...          print(f\"{k}={v!r}\")\n    ...\n    >>> a2 = argset(my_func2)\n    >>> \"foo\" in a2\n    True\n    >>> \"quux\" in a2\n    True\n    >>> a2.select({\"foo\": 42, \"bar\": 23, \"quux\": 17})\n    {'foo': 42, 'bar': 23, 'quux': 17}\n    >>> my_func2(**a2.select({\"foo\": 42, \"bar\": 23, \"quux\": 17}))\n    foo=42\n    bar=23\n    quux=17\n\n\nAPI\n===\n\n.. code:: python\n\n    argset(func: Callable) -> ArgSet\n\nInspects a callable and returns a summary of its arguments as an ``ArgSet``\n\n.. code:: python\n\n    class ArgSet\n\nA representation of the arguments taken by a callable.  It has the following\nattributes & properties:\n\n``required_positional_only: int``\n    The number of arguments that are positional-only and do not have default\n    values\n\n``optional_positional_only: int``\n    The number of arguments that are positional-only and have a default value\n\n``positional_only: int``\n    The total number of positional-only arguments\n\n``required_args: frozenset[str]``\n    The names of all positional-or-keyword or keyword-only arguments that do\n    not have default values\n\n``optional_args: frozenset[str]``\n    The names of all positional-or-keyword or keyword-only arguments that have\n    default values\n\n``argnames: frozenset[str]``\n    The names of all positional-or-keyword or keyword-only arguments\n\n``takes_args: bool``\n    Whether the callable has an argument of the form ``*args``\n\n``takes_kwargs: bool``\n    Whether the callable has an argument of the form ``**kwargs``\n\n``ArgSet`` objects support the ``in`` operator; an expression of the form\n``argname in a`` returns ``True`` iff ``argname`` is in ``a.argnames`` or\n``a.takes_kwargs`` is ``True``.\n\n``ArgSet`` objects have the following methods:\n\n.. code:: python\n\n    ArgSet.select(kwargs: Dict[str, Any]) -> Dict[str, Any]\n\nReturns all items in ``kwargs`` where the key is the name of a\npositional-or-keyword or keyword-only argument accepted by the callable.  If\n``takes_kwargs`` is ``True``, the return value is a copy of ``kwargs``.\n\n.. code:: python\n\n    ArgSet.missing(kwargs: Dict[str, Any]) -> FrozenSet[str]\n\nReturns all keys in ``required_args`` that do not appear in ``kwargs``\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Simple callable argument inspection & filtering",
    "version": "0.1.1.post1",
    "project_urls": {
        "Bug Tracker": "https://github.com/jwodder/argset/issues",
        "Source Code": "https://github.com/jwodder/argset"
    },
    "split_keywords": [
        "arguments",
        " callable",
        " inspect",
        " keyword arguments",
        " signature"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "73df1a4eb2d1a4b030413d7997e3447567dcbbe69100bcb623ffb4321adf636a",
                "md5": "48615db84121df0ef8872d446a1f165e",
                "sha256": "49e05570cf97c39c002c1e3d689fb21e11a1f29eb44529d073c1e13a64c8df32"
            },
            "downloads": -1,
            "filename": "argset-0.1.1.post1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "48615db84121df0ef8872d446a1f165e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 5139,
            "upload_time": "2025-10-28T12:42:50",
            "upload_time_iso_8601": "2025-10-28T12:42:50.963342Z",
            "url": "https://files.pythonhosted.org/packages/73/df/1a4eb2d1a4b030413d7997e3447567dcbbe69100bcb623ffb4321adf636a/argset-0.1.1.post1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "052a2de8543f155c71d66d943f7c924ac8135503414c1b3fb79350763cd8b3b9",
                "md5": "87444ad6a9c75d3e7083f447cac3775f",
                "sha256": "c2b65b7a11f5d4d100c7df9fed774df13dd10d2a1dbbf21881e496bbb8ed87bf"
            },
            "downloads": -1,
            "filename": "argset-0.1.1.post1.tar.gz",
            "has_sig": false,
            "md5_digest": "87444ad6a9c75d3e7083f447cac3775f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 5913,
            "upload_time": "2025-10-28T12:42:51",
            "upload_time_iso_8601": "2025-10-28T12:42:51.765952Z",
            "url": "https://files.pythonhosted.org/packages/05/2a/2de8543f155c71d66d943f7c924ac8135503414c1b3fb79350763cd8b3b9/argset-0.1.1.post1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-28 12:42:51",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jwodder",
    "github_project": "argset",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "argset"
}
        
Elapsed time: 1.74828s