[![Build Status](https://asottile.visualstudio.com/asottile/_apis/build/status/asottile.classify-imports?branchName=main)](https://asottile.visualstudio.com/asottile/_build/latest?definitionId=74&branchName=main)
[![Azure DevOps coverage](https://img.shields.io/azure-devops/coverage/asottile/asottile/74/main.svg)](https://dev.azure.com/asottile/asottile/_build/latest?definitionId=74&branchName=main)
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/asottile/classify-imports/main.svg)](https://results.pre-commit.ci/latest/github/asottile/classify-imports/main)
classify-imports
================
Utilities for refactoring imports in python-like syntax.
## installation
`pip install classify-imports`
## examples
### splitting an import object
```pycon
>>> from classify_imports import import_obj_from_str
>>> obj = import_obj_from_str('import foo, bar, baz')
>>> [str(i) for i in obj.split()]
['import foo\n', 'import bar\n', 'import baz\n']
```
### sorting import objects
```pycon
# Or to partition into blocks (even with mixed imports)
>>> import pprint
>>> from classify_imports import import_obj_from_str, sort
>>> partitioned = sort(
[
import_obj_from_str('from classify_imports import sort'),
import_obj_from_str('import sys'),
import_obj_from_str('from pyramid.view import view_config'),
import_obj_from_str('import cached_property'),
],
)
>>> pprint.pprint(partitioned)
(
(import_obj_from_str('import sys\n'),),
(
import_obj_from_str('import cached_property\n'),
import_obj_from_str('from pyramid.view import view_config\n'),
),
(import_obj_from_str('from classify_imports import sort\n'),),
)
```
### classify a module
```pycon
>>> from classify_imports import classify_base, import_obj_from_str, Classified
>>> classify_base('__future__')
'FUTURE'
>>> classify_base('classify_imports')
'APPLICATION'
>>> classify_base('pyramid')
'THIRD_PARTY'
>>> classify_base('os')
'BUILTIN'
>>> classify_base(import_obj_from_str('import os.path').module_base)
'BUILTIN'
>>> Classified.APPLICATION
'APPLICATION'
>>> Classified.order
('FUTURE', 'BUILTIN', 'THIRD_PARTY', 'APPLICATION')
```
Raw data
{
"_id": null,
"home_page": "https://github.com/asottile/classify-imports",
"name": "classify-imports",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "",
"author": "Anthony Sottile",
"author_email": "asottile@umich.edu",
"download_url": "https://files.pythonhosted.org/packages/7e/b6/6cdc486fced92110a8166aa190b7d60435165119990fc2e187a56d15144b/classify_imports-4.2.0.tar.gz",
"platform": null,
"description": "[![Build Status](https://asottile.visualstudio.com/asottile/_apis/build/status/asottile.classify-imports?branchName=main)](https://asottile.visualstudio.com/asottile/_build/latest?definitionId=74&branchName=main)\n[![Azure DevOps coverage](https://img.shields.io/azure-devops/coverage/asottile/asottile/74/main.svg)](https://dev.azure.com/asottile/asottile/_build/latest?definitionId=74&branchName=main)\n[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/asottile/classify-imports/main.svg)](https://results.pre-commit.ci/latest/github/asottile/classify-imports/main)\n\nclassify-imports\n================\n\nUtilities for refactoring imports in python-like syntax.\n\n## installation\n\n`pip install classify-imports`\n\n## examples\n\n### splitting an import object\n\n```pycon\n>>> from classify_imports import import_obj_from_str\n>>> obj = import_obj_from_str('import foo, bar, baz')\n>>> [str(i) for i in obj.split()]\n['import foo\\n', 'import bar\\n', 'import baz\\n']\n```\n\n### sorting import objects\n\n```pycon\n# Or to partition into blocks (even with mixed imports)\n>>> import pprint\n>>> from classify_imports import import_obj_from_str, sort\n>>> partitioned = sort(\n [\n import_obj_from_str('from classify_imports import sort'),\n import_obj_from_str('import sys'),\n import_obj_from_str('from pyramid.view import view_config'),\n import_obj_from_str('import cached_property'),\n ],\n)\n>>> pprint.pprint(partitioned)\n(\n (import_obj_from_str('import sys\\n'),),\n (\n import_obj_from_str('import cached_property\\n'),\n import_obj_from_str('from pyramid.view import view_config\\n'),\n ),\n (import_obj_from_str('from classify_imports import sort\\n'),),\n)\n\n```\n\n### classify a module\n\n```pycon\n>>> from classify_imports import classify_base, import_obj_from_str, Classified\n>>> classify_base('__future__')\n'FUTURE'\n>>> classify_base('classify_imports')\n'APPLICATION'\n>>> classify_base('pyramid')\n'THIRD_PARTY'\n>>> classify_base('os')\n'BUILTIN'\n>>> classify_base(import_obj_from_str('import os.path').module_base)\n'BUILTIN'\n>>> Classified.APPLICATION\n'APPLICATION'\n>>> Classified.order\n('FUTURE', 'BUILTIN', 'THIRD_PARTY', 'APPLICATION')\n```\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Utilities for refactoring imports in python-like syntax.",
"version": "4.2.0",
"project_urls": {
"Homepage": "https://github.com/asottile/classify-imports"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "8ba5f752351ea2652744f711bf5d478f00e2ceeeff0def6316ea9e1bfa18d8d2",
"md5": "44409567ff808043a36a84c9500bc8d6",
"sha256": "dbbc264b70a470ed8c6c95976a11dfb8b7f63df44ed1af87328bbed2663f5161"
},
"downloads": -1,
"filename": "classify_imports-4.2.0-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "44409567ff808043a36a84c9500bc8d6",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": ">=3.7",
"size": 5403,
"upload_time": "2022-07-31T22:59:10",
"upload_time_iso_8601": "2022-07-31T22:59:10.799966Z",
"url": "https://files.pythonhosted.org/packages/8b/a5/f752351ea2652744f711bf5d478f00e2ceeeff0def6316ea9e1bfa18d8d2/classify_imports-4.2.0-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "7eb66cdc486fced92110a8166aa190b7d60435165119990fc2e187a56d15144b",
"md5": "37447033e241d596828133c2c7c704a3",
"sha256": "7abfb7ea92149b29d046bd34573d247ba6e68cc28100c801eba4af17964fc40e"
},
"downloads": -1,
"filename": "classify_imports-4.2.0.tar.gz",
"has_sig": false,
"md5_digest": "37447033e241d596828133c2c7c704a3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 5188,
"upload_time": "2022-07-31T22:59:12",
"upload_time_iso_8601": "2022-07-31T22:59:12.139709Z",
"url": "https://files.pythonhosted.org/packages/7e/b6/6cdc486fced92110a8166aa190b7d60435165119990fc2e187a56d15144b/classify_imports-4.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-07-31 22:59:12",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "asottile",
"github_project": "classify-imports",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "classify-imports"
}