« Back to Index

[Flake8 Import Order]

View original Gist on GitHub

Tags: #python #flake8 #import #order

Flake8 Import Order.md

; tox.ini

[flake8]
max-line-length = 120
import-order-style = cryptography
application-import-names = foo

Note: don’t try and put flake8-import-order configuration under its own section (e.g. [flake8-import-order]) as Flake8 doesn’t look at values outside of its own block (i.e. [flake8]) – see explanation here.

# standard library packages/modules

import asyncio
import time

# third-party packages/modules

from tornado.httpclient import AsyncHTTPClient
from tornado.ioloop import IOLoop

# application packages/modules

from foo.bar import baz

AsyncHTTPClient.configure(None, defaults=dict(user_agent="MyUserAgent"))
http_client = AsyncHTTPClient()


async def do_thing():
    await asyncio.sleep(1)
    time.sleep(1)
    response = await http_client.fetch("https://www.integralist.co.uk")
    print(response.code)
    baz()

io_loop = IOLoop.current()
io_loop.run_sync(do_thing)

Note: to ensure foo package isn’t identified as “Third-Party” we have to specify it as “Application” via configuration with application-import-names, which is a comma-separated list of your own application packages/modules.