{"id":18468732,"url":"https://github.com/pycqa/flake8-import-order","last_synced_at":"2025-04-14T11:28:07.038Z","repository":{"id":15072745,"uuid":"17799097","full_name":"PyCQA/flake8-import-order","owner":"PyCQA","description":"Flake8 plugin that checks import order against various Python Style Guides","archived":false,"fork":false,"pushed_at":"2024-02-08T12:24:35.000Z","size":247,"stargazers_count":276,"open_issues_count":15,"forks_count":72,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-31T01:12:29.615Z","etag":null,"topics":["flake8","flake8-extensions","linter-flake8","linter-plugin","pylama","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PyCQA.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-03-16T12:46:09.000Z","updated_at":"2025-03-17T15:42:24.000Z","dependencies_parsed_at":"2024-06-18T12:31:57.965Z","dependency_job_id":"c8078084-c08d-435d-89e4-905d1ff7999a","html_url":"https://github.com/PyCQA/flake8-import-order","commit_stats":{"total_commits":255,"total_committers":51,"mean_commits":5.0,"dds":0.7098039215686274,"last_synced_commit":"77de645f66aef4636503af207b3bd325fadfb086"},"previous_names":["public/flake8-import-order"],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PyCQA%2Fflake8-import-order","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PyCQA%2Fflake8-import-order/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PyCQA%2Fflake8-import-order/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PyCQA%2Fflake8-import-order/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PyCQA","download_url":"https://codeload.github.com/PyCQA/flake8-import-order/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247578558,"owners_count":20961271,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["flake8","flake8-extensions","linter-flake8","linter-plugin","pylama","python"],"created_at":"2024-11-06T10:08:02.064Z","updated_at":"2025-04-07T02:20:16.661Z","avatar_url":"https://github.com/PyCQA.png","language":"Python","readme":"flake8-import-order\n===================\n\n|Build Status|\n\nA `flake8 \u003chttp://flake8.readthedocs.org/en/latest/\u003e`__ and `Pylama\n\u003chttps://github.com/klen/pylama\u003e`__ plugin that checks the ordering of\nyour imports. It does not check anything else about the\nimports. Merely that they are grouped and ordered correctly.\n\nIn general stdlib comes first, then 3rd party, then local packages,\nand that each group is individually alphabetized, however this depends\non the style used. Flake8-Import-Order supports a number of `styles\n\u003c#styles\u003e`_ and is extensible allowing for `custom styles\n\u003c#extending-styles\u003e`_.\n\nThis plugin was originally developed to match the style preferences of\nthe `cryptography \u003chttps://github.com/pyca/cryptography\u003e`__ project,\nwith this style remaining the default.\n\nWarnings\n--------\n\nThis package adds 4 new flake8 warnings\n\n-  ``I100``: Your import statements are in the wrong order.\n-  ``I101``: The names in your from import are in the wrong order.\n-  ``I201``: Missing newline between import groups.\n-  ``I202``: Additional newline in a group of imports.\n\nStyles\n------\n\nThe following styles are directly supported,\n\n* ``cryptography`` - see an `example \u003chttps://github.com/PyCQA/flake8-import-order/blob/master/tests/test_cases/complete_cryptography.py\u003e`__\n* ``google`` - style described in `Google Style Guidelines \u003chttps://google.github.io/styleguide/pyguide.html?showone=Imports_formatting#313-imports-formatting\u003e`__, see an `example \u003chttps://github.com/PyCQA/flake8-import-order/blob/master/tests/test_cases/complete_google.py\u003e`__\n* ``smarkets`` - style as ``google`` only with `import` statements before `from X import ...` statements, see an `example \u003chttps://github.com/PyCQA/flake8-import-order/blob/master/tests/test_cases/complete_smarkets.py\u003e`__\n* ``appnexus`` - style as ``google`` only with `import` statements for packages local to your company or organisation coming after `import` statements for third-party packages, see an `example \u003chttps://github.com/PyCQA/flake8-import-order/blob/master/tests/test_cases/complete_appnexus.py\u003e`__\n* ``edited`` - see an `example \u003chttps://github.com/PyCQA/flake8-import-order/blob/master/tests/test_cases/complete_edited.py\u003e`__\n* ``pycharm`` - style as ``smarkets`` only with case sensitive sorting imported names\n* ``pep8`` - style that only enforces groups without enforcing the order within the groups\n\nYou can also `add your own style \u003c#extending-styles\u003e`_ by extending ``Style``\nclass.\n\nConfiguration\n-------------\n\nYou will want to set the ``application-import-names`` option to a\ncomma separated list of names that should be considered local to your\napplication. These will be used to help categorise your import\nstatements into the correct groups. Note that relative imports are\nalways considered local.\n\nYou will want to set the ``application-package-names`` option to a\ncomma separated list of names that should be considered local to your\ncompany or organisation, but which are obtained using some sort of\npackage manager like Pip, Apt, or Yum.  Typically, code representing\nthe values listed in this option is located in a different repository\nthan the code being developed.  This option is only accepted in the\nsupported ``appnexus`` or ``edited`` styles or in any style that\naccepts application package names.\n\nThe ``application-import-names`` and ``application-package-names`` can\ncontain namespaced packages or even exact nested module names. (This\nis possible with 0.16 onwards).\n\n``import-order-style`` controls what style the plugin follows\n(``cryptography`` is the default).\n\nLimitations\n-----------\n\nCurrently these checks are limited to module scope imports only.\nConditional imports in module scope will also be ignored.\n\nClassification of an imported module is achieved by checking the\nmodule against a stdlib list and then if there is no match against the\n``application-import-names`` list and ``application-package-names`` if\nthe style accepts application-package names. Only if none of these\nlists contain the imported module will it be classified as third\nparty.\n\nThese checks only consider an import against its previous import,\nrather than considering all the imports together. This means that\n``I100`` errors are only raised for the latter of adjacent imports out\nof order. For example,\n\n.. code-block:: python\n\n    import X.B\n    import X  # I100\n    import X.A\n\nonly ``import X`` raises an ``I100`` error, yet ``import X.A`` is also\nout of order compared with the ``import X.B``.\n\nImported modules are classified as stdlib if the module is in a\nvendored list of stdlib modules. This list is based on the latest\nrelease of Python and hence the results can be misleading. This list\nis also the same for all Python versions because otherwise it would\nbe impossible to write programs that work under both Python 2 and 3\n*and* pass the import order check.\n\nThe ``I202`` check will consider any blank line between imports to\ncount, even if the line is not contextually related to the\nimports. For example,\n\n.. code-block:: python\n\n    import logging\n    try:\n        from logging import NullHandler\n    except ImportError:\n        class NullHandler(logging.Handler):\n            \"\"\"Shim for version of Python \u003c 2.7.\"\"\"\n\n            def emit(self, record):\n                pass\n    import sys  # I202 due to the blank line before the 'def emit'\n\nwill trigger a ``I202`` error despite the blank line not being\ncontextually related.\n\nExtending styles\n----------------\n\nYou can add your own style by extending ``flake8_import_order.styles.Style``\nclass. Here's an example:\n\n.. code-block:: python\n\n    from flake8_import_order.styles import Cryptography\n\n\n    class ReversedCryptography(Cryptography):\n        # Note that Cryptography is a subclass of Style.\n\n        @staticmethod\n        def sorted_names(names):\n            return reversed(Cryptography.sorted_names(names))\n\nBy default there are five import groupings or sections; future,\nstdlib, third party, application, and relative imports. A style can\nchoose to accept another grouping, application-package, by setting the\n``Style`` class variable ``accepts_application_package_names`` to\nTrue, e.g.\n\n.. code-block:: python\n\n    class PackageNameCryptography(Cryptography):\n        accepts_application_package_names = True\n\nTo make flake8-import-order able to discover your extended style, you need to\nregister it as ``flake8_import_order.styles`` using setuptools' `entry points\n\u003chttps://setuptools.readthedocs.io/en/latest/pkg_resources.html#entry-points\u003e`__\nmechanism:\n\n.. code-block:: python\n\n    # setup.py of your style package\n    setup(\n        name='flake8-import-order-reversed-cryptography',\n        ...,\n        entry_points={\n            'flake8_import_order.styles': [\n                'reversed = reversedcryptography:ReversedCryptography',\n                # 'reversed' is a style name.  You can pass it to\n                # --import-order-style option\n                # 'reversedcryptography:ReversedCryptography' is an import path\n                # of your extended style class.\n            ]\n        }\n    )\n\n.. |Build Status| image:: https://travis-ci.org/PyCQA/flake8-import-order.svg?branch=master\n   :target: https://travis-ci.org/PyCQA/flake8-import-order\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpycqa%2Fflake8-import-order","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpycqa%2Fflake8-import-order","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpycqa%2Fflake8-import-order/lists"}