thrift-pyi


Namethrift-pyi JSON
Version 0.9.0 PyPI version JSON
download
home_pagehttps://github.com/unmade/thrift-pyi
SummaryThis is simple `.pyi` stubs generator from thrift interfaces
upload_time2024-04-28 08:15:20
maintainerNone
docs_urlNone
authorAleksei Maslakov
requires_python<4.0,>=3.7
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.7",
    "maintainer_email": null,
    "keywords": null,
    "author": "Aleksei Maslakov",
    "author_email": "lesha.maslakov@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/46/be/65e4eda7e7bcad6f59dcd6f0e65d5e0934d28d2f5ac828dc91435d7febce/thrift_pyi-0.9.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": "0.9.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": "b54bff1956860536490638a0a2c81ba60089e2858262e69980afe9ea9c78c38a",
                "md5": "5d13b99ec8fb7cd17b9ea23249a9a620",
                "sha256": "67a89e072b9bedd57c45b242d63987f11dfc1a0e1dcdc88b13a08f5383c6f85f"
            },
            "downloads": -1,
            "filename": "thrift_pyi-0.9.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5d13b99ec8fb7cd17b9ea23249a9a620",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.7",
            "size": 10987,
            "upload_time": "2024-04-28T08:15:18",
            "upload_time_iso_8601": "2024-04-28T08:15:18.257020Z",
            "url": "https://files.pythonhosted.org/packages/b5/4b/ff1956860536490638a0a2c81ba60089e2858262e69980afe9ea9c78c38a/thrift_pyi-0.9.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "46be65e4eda7e7bcad6f59dcd6f0e65d5e0934d28d2f5ac828dc91435d7febce",
                "md5": "c8aa599046fb5faba1d5d1939be4ae72",
                "sha256": "7dac9a3fcb82c36e90904e0f47c9bb6db942c6145dffd0728f263bcb85c7bbea"
            },
            "downloads": -1,
            "filename": "thrift_pyi-0.9.0.tar.gz",
            "has_sig": false,
            "md5_digest": "c8aa599046fb5faba1d5d1939be4ae72",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.7",
            "size": 9274,
            "upload_time": "2024-04-28T08:15:20",
            "upload_time_iso_8601": "2024-04-28T08:15:20.032290Z",
            "url": "https://files.pythonhosted.org/packages/46/be/65e4eda7e7bcad6f59dcd6f0e65d5e0934d28d2f5ac828dc91435d7febce/thrift_pyi-0.9.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-28 08:15: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.21966s