Skip to main content
Help us improve PyPI by participating in user testing. All experience levels needed!

A Python import organizer

Project description

Imporganizer organizes any imports of Python files found in the start of the file, putting them in alphabetic order. Comments or docstrings in the first lines are not supported yet. This feature is planned.

Requisites

Your imports need to be formatted in these rules:

  • They must be at the start of the file (blank lines before the first import will be removed).
  • They must use forward-slash to define multi-line imports.
  • They must be separated from the rest of the file (Python code) by 2 empty lines.

GOOD:

from django.models import Model, \
    Manager

BAD:

from django.models import (Model,
    Manager)

Usage

Install using pip:

$ pip install imporganizer

Use with the command line (main usage):

$ imporganizer organize-this.py --third-party=package1,package2 --homemade=package3,package4

Update the standard packages list with:

$ imporganizer --update-builtin

You can’t update the builtin list and organize a file with a single command, but this is a feature in our roadmap.

Output

They will be categorized by:

  • Standard: all packages included with the default distribution of Python.
  • Third party: all packages not standard and not internal to the project.
  • Homemade: dependencies, packages and modules internal to the project.

To be able to categorize your packages this way, you must inform which ones are third party and which ones are internal to the project. You do this by the command line:

imporganizer organize-this.py --third-party=package1,package2 --homemade=package3,package4

For an input like this:

from django.forms import Form, \
    CharField
from textwrap import dedent

from django.db.models import Model
import sys
import os
import internal

import another_internal


print('hey')

The output will be:

import os
import sys
from textwrap import dedent

from django.db.models import Model
from django.forms import CharField, \
    Form

import another_internal
import internal


print('hey')

It will assume a maximum line length of 79 characters.

Project details


Release history Release notifications

This version
History Node

1.1.1

History Node

1.1

History Node

1.0.6

History Node

1.0.5

History Node

1.0.4

History Node

1.0.3

History Node

1.0.2

History Node

1.0.1

History Node

1.0.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
imporganizer-1.1.1.tar.gz (6.1 kB) Copy SHA256 hash SHA256 Source None Mar 2, 2016

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page