thrift-pyi


Namethrift-pyi JSON
Version 1.1.0 PyPI version JSON
download
home_pagehttps://github.com/unmade/thrift-pyi
SummaryThis is simple `.pyi` stubs generator from thrift interfaces
upload_time2024-12-17 19:11:20
maintainerNone
docs_urlNone
authorAleksei Maslakov
requires_python<4.0,>=3.9
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            ========
Overview
========

.. start-badges

.. image:: https://github.com/unmade/thrift-pyi/workflows/lint%20and%20test/badge.svg?branch=master
    :alt: Build Status
    :target: https://github.com/unmade/thrift-pyi/blob/master/.github/workflows/lint-and-test.yml

.. image:: https://codecov.io/github/unmade/thrift-pyi/coverage.svg?branch=master
    :alt: Coverage Status
    :target: https://codecov.io/github/unmade/thrift-pyi

.. image:: https://api.codacy.com/project/badge/Grade/487480f045594e148309e8b7f1f71351
    :alt: Codacy Badge
    :target: https://app.codacy.com/app/unmade/thrift-pyi

.. image:: https://requires.io/github/unmade/thrift-pyi/requirements.svg?branch=master
    :alt: Requirements Status
    :target: https://requires.io/github/unmade/thrift-pyi/requirements/?branch=master

.. image:: https://img.shields.io/pypi/v/thrift-pyi.svg
    :alt: PyPI Package latest release
    :target: https://pypi.org/project/thrift-pyi

.. image:: https://img.shields.io/pypi/wheel/thrift-pyi.svg
    :alt: PyPI Wheel
    :target: https://pypi.org/project/thrift-pyi

.. image:: https://img.shields.io/pypi/pyversions/thrift-pyi.svg
    :alt: Supported versions
    :target: https://pypi.org/project/thrift-pyi

.. image:: https://img.shields.io/badge/License-MIT-purple.svg
    :alt: MIT License
    :target: https://github.com/unmade/thrift-pyi/blob/master/LICENSE

.. end-badges

This is simple `.pyi` stubs generator from thrift interfaces.
Motivation for this project is to have autocomplete and type checking
for dynamically loaded thrift interfaces

Installation
============

.. code-block:: bash

    pip install thrift-pyi

Quickstart
==========

Sample usage:

.. code-block:: bash

    $ thriftpyi example/interfaces --output example/app/interfaces

Additionally to generated stubs you might want to create `__init__.py` that will load thrift interfaces, for example:

.. code-block:: python

    from pathlib import Path
    from types import ModuleType
    from typing import Dict

    import thriftpy2

    _interfaces_path = Path("example/interfaces")
    _interfaces: Dict[str, ModuleType] = {}


    def __getattr__(name):
        try:
            return _interfaces[name]
        except KeyError:
            interface = thriftpy2.load(str(_interfaces_path.joinpath(f"{name}.thrift")))
            _interfaces[name] = interface
            return interface


To see more detailed example of usage refer to `example app <https://github.com/unmade/thrift-pyi/blob/master/example>`_

--strict-optional
-----------------

Python and thrift are very different at argument handling.
For example in thrift the following will be correct declaration:

.. code-block:: thrift

    struct TodoItem {
        1: required i32 id
        3: optional i32 type = 1
        2: required string text
    }

In python, fields without default values cannot appear after fields with default
values. Therefore by default all fields are optional with default to None.
This is compliant to `thriftpy2 <https://github.com/Thriftpy/thriftpy2>`_.

However, if you want more strict behaviour you can specify `--strict-optional` option.
For the case above, the following stubs will be generated:

.. code-block:: python

    from dataclasses import dataclass

    @dataclass
    class TodoItem:
        id: int
        type: int = 1
        text: str

Development
===========

To install pre-commit hooks::

    pre-commit install

To run the all tests run::

    tox

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/unmade/thrift-pyi",
    "name": "thrift-pyi",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "Aleksei Maslakov",
    "author_email": "lesha.maslakov@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/8b/a5/20d3dddfbbb5abed1f1a67908e0981489dcd73fb7c22522292e6f0a8b327/thrift_pyi-1.1.0.tar.gz",
    "platform": null,
    "description": "========\nOverview\n========\n\n.. start-badges\n\n.. image:: https://github.com/unmade/thrift-pyi/workflows/lint%20and%20test/badge.svg?branch=master\n    :alt: Build Status\n    :target: https://github.com/unmade/thrift-pyi/blob/master/.github/workflows/lint-and-test.yml\n\n.. image:: https://codecov.io/github/unmade/thrift-pyi/coverage.svg?branch=master\n    :alt: Coverage Status\n    :target: https://codecov.io/github/unmade/thrift-pyi\n\n.. image:: https://api.codacy.com/project/badge/Grade/487480f045594e148309e8b7f1f71351\n    :alt: Codacy Badge\n    :target: https://app.codacy.com/app/unmade/thrift-pyi\n\n.. image:: https://requires.io/github/unmade/thrift-pyi/requirements.svg?branch=master\n    :alt: Requirements Status\n    :target: https://requires.io/github/unmade/thrift-pyi/requirements/?branch=master\n\n.. image:: https://img.shields.io/pypi/v/thrift-pyi.svg\n    :alt: PyPI Package latest release\n    :target: https://pypi.org/project/thrift-pyi\n\n.. image:: https://img.shields.io/pypi/wheel/thrift-pyi.svg\n    :alt: PyPI Wheel\n    :target: https://pypi.org/project/thrift-pyi\n\n.. image:: https://img.shields.io/pypi/pyversions/thrift-pyi.svg\n    :alt: Supported versions\n    :target: https://pypi.org/project/thrift-pyi\n\n.. image:: https://img.shields.io/badge/License-MIT-purple.svg\n    :alt: MIT License\n    :target: https://github.com/unmade/thrift-pyi/blob/master/LICENSE\n\n.. end-badges\n\nThis is simple `.pyi` stubs generator from thrift interfaces.\nMotivation for this project is to have autocomplete and type checking\nfor dynamically loaded thrift interfaces\n\nInstallation\n============\n\n.. code-block:: bash\n\n    pip install thrift-pyi\n\nQuickstart\n==========\n\nSample usage:\n\n.. code-block:: bash\n\n    $ thriftpyi example/interfaces --output example/app/interfaces\n\nAdditionally to generated stubs you might want to create `__init__.py` that will load thrift interfaces, for example:\n\n.. code-block:: python\n\n    from pathlib import Path\n    from types import ModuleType\n    from typing import Dict\n\n    import thriftpy2\n\n    _interfaces_path = Path(\"example/interfaces\")\n    _interfaces: Dict[str, ModuleType] = {}\n\n\n    def __getattr__(name):\n        try:\n            return _interfaces[name]\n        except KeyError:\n            interface = thriftpy2.load(str(_interfaces_path.joinpath(f\"{name}.thrift\")))\n            _interfaces[name] = interface\n            return interface\n\n\nTo see more detailed example of usage refer to `example app <https://github.com/unmade/thrift-pyi/blob/master/example>`_\n\n--strict-optional\n-----------------\n\nPython and thrift are very different at argument handling.\nFor example in thrift the following will be correct declaration:\n\n.. code-block:: thrift\n\n    struct TodoItem {\n        1: required i32 id\n        3: optional i32 type = 1\n        2: required string text\n    }\n\nIn python, fields without default values cannot appear after fields with default\nvalues. Therefore by default all fields are optional with default to None.\nThis is compliant to `thriftpy2 <https://github.com/Thriftpy/thriftpy2>`_.\n\nHowever, if you want more strict behaviour you can specify `--strict-optional` option.\nFor the case above, the following stubs will be generated:\n\n.. code-block:: python\n\n    from dataclasses import dataclass\n\n    @dataclass\n    class TodoItem:\n        id: int\n        type: int = 1\n        text: str\n\nDevelopment\n===========\n\nTo install pre-commit hooks::\n\n    pre-commit install\n\nTo run the all tests run::\n\n    tox\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "This is simple `.pyi` stubs generator from thrift interfaces",
    "version": "1.1.0",
    "project_urls": {
        "Homepage": "https://github.com/unmade/thrift-pyi",
        "Repository": "https://github.com/unmade/thrift-pyi"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a302b682adb52a4fe45d9acb27bab29fe16c3f78a0b1b12adfbc219485fdaf0f",
                "md5": "8d6df0fea138e807f8bcacdb4ab2d8cb",
                "sha256": "c57279ac6764a97bb7889dd2165db441c52d7bc3bd45f1128125c617dc837568"
            },
            "downloads": -1,
            "filename": "thrift_pyi-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8d6df0fea138e807f8bcacdb4ab2d8cb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 11144,
            "upload_time": "2024-12-17T19:11:17",
            "upload_time_iso_8601": "2024-12-17T19:11:17.130123Z",
            "url": "https://files.pythonhosted.org/packages/a3/02/b682adb52a4fe45d9acb27bab29fe16c3f78a0b1b12adfbc219485fdaf0f/thrift_pyi-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8ba520d3dddfbbb5abed1f1a67908e0981489dcd73fb7c22522292e6f0a8b327",
                "md5": "58c1207b6aecf57733ddf14c5acfded1",
                "sha256": "4853e6bd1858b4a32dcc3323370c9f6c9e581d5bb7c63c7d16f3d14e026a0160"
            },
            "downloads": -1,
            "filename": "thrift_pyi-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "58c1207b6aecf57733ddf14c5acfded1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 9531,
            "upload_time": "2024-12-17T19:11:20",
            "upload_time_iso_8601": "2024-12-17T19:11:20.030199Z",
            "url": "https://files.pythonhosted.org/packages/8b/a5/20d3dddfbbb5abed1f1a67908e0981489dcd73fb7c22522292e6f0a8b327/thrift_pyi-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-17 19:11:20",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "unmade",
    "github_project": "thrift-pyi",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "tox": true,
    "lcname": "thrift-pyi"
}
        
Elapsed time: 0.44572s