diff --git a/CHANGELOG b/CHANGELOG
index 92806ad..e3cc518 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,6 +2,11 @@
 # All notable changes to this project will be documented in this file.
 # This project adheres to [Semantic Versioning](http://semver.org/).
 
+## Unreleased
+### Added
+- The `BLANK_LINE_BEFORE_MODULE_DOCSTRING` knob adds a blank line before a
+  module's docstring.
+
 ## [0.21.0] 2018-03-18
 ### Added
 - Introduce a new option of formatting multiline literals. Add
diff --git a/README.rst b/README.rst
index 3b43d29..ccc74d9 100644
--- a/README.rst
+++ b/README.rst
@@ -322,6 +322,9 @@ Knobs
             def method():
                 pass
 
+``BLANK_LINE_BEFORE_MODULE_DOCSTRING``
+    Insert a blank line before a module docstring.
+
 ``BLANK_LINE_BEFORE_CLASS_DOCSTRING``
     Insert a blank line before a class-level docstring.
 
diff --git a/yapf/yapflib/reformatter.py b/yapf/yapflib/reformatter.py
index a4965ab..0485d7e 100644
--- a/yapf/yapflib/reformatter.py
+++ b/yapf/yapflib/reformatter.py
@@ -473,6 +473,10 @@ def _CalculateNumberOfNewlines(first_token, indent_depth, prev_uwline,
         style.Get('BLANK_LINE_BEFORE_CLASS_DOCSTRING')):
       # Enforce a blank line before a class's docstring.
       return ONE_BLANK_LINE
+    elif (prev_uwline.first.value.startswith('#') and
+          style.Get('BLANK_LINE_BEFORE_MODULE_DOCSTRING')):
+      # Enforce a blank line before a module's docstring.
+      return ONE_BLANK_LINE
     # The docstring shouldn't have a newline before it.
     return NO_BLANK_LINES
 
diff --git a/yapf/yapflib/style.py b/yapf/yapflib/style.py
index 5f2fdac..7fd2177 100644
--- a/yapf/yapflib/style.py
+++ b/yapf/yapflib/style.py
@@ -71,6 +71,8 @@ _STYLE_HELP = dict(
             ..."""),
     BLANK_LINE_BEFORE_CLASS_DOCSTRING=textwrap.dedent("""\
       Insert a blank line before a class-level docstring."""),
+    BLANK_LINE_BEFORE_MODULE_DOCSTRING=textwrap.dedent("""\
+      Insert a blank line before a module docstring."""),
     BLANK_LINES_AROUND_TOP_LEVEL_DEFINITION=textwrap.dedent("""\
       Number of blank lines surrounding top-level function and class
       definitions."""),
@@ -261,6 +263,7 @@ def CreatePEP8Style():
       ALLOW_SPLIT_BEFORE_DICT_VALUE=True,
       BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF=False,
       BLANK_LINE_BEFORE_CLASS_DOCSTRING=False,
+      BLANK_LINE_BEFORE_MODULE_DOCSTRING=False,
       BLANK_LINES_AROUND_TOP_LEVEL_DEFINITION=2,
       COALESCE_BRACKETS=False,
       COLUMN_LIMIT=79,
@@ -406,6 +409,7 @@ _STYLE_OPTION_VALUE_CONVERTER = dict(
     ALLOW_SPLIT_BEFORE_DICT_VALUE=_BoolConverter,
     BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF=_BoolConverter,
     BLANK_LINE_BEFORE_CLASS_DOCSTRING=_BoolConverter,
+    BLANK_LINE_BEFORE_MODULE_DOCSTRING=_BoolConverter,
     BLANK_LINES_AROUND_TOP_LEVEL_DEFINITION=int,
     COALESCE_BRACKETS=_BoolConverter,
     COLUMN_LIMIT=int,

diff --git a/yapftests/reformatter_basic_test.py b/yapftests/reformatter_basic_test.py
index a1ca779..01ed3d9 100644
--- a/yapftests/reformatter_basic_test.py
+++ b/yapftests/reformatter_basic_test.py
@@ -2218,6 +2218,59 @@ s = 'foo \\
     finally:
       style.SetGlobalStyle(style.CreateChromiumStyle())
 
+  def testBlankLineBeforeModuleDocstring(self):
+    unformatted_code = textwrap.dedent('''\
+        #!/usr/bin/env python
+        # -*- coding: utf-8 name> -*-
+
+        """Some module docstring."""
+
+
+        def foobar():
+          pass
+        ''')
+    expected_code = textwrap.dedent('''\
+        #!/usr/bin/env python
+        # -*- coding: utf-8 name> -*-
+        """Some module docstring."""
+
+
+        def foobar():
+          pass
+        ''')
+    uwlines = yapf_test_helper.ParseAndUnwrap(unformatted_code)
+    self.assertEqual(expected_code, reformatter.Reformat(uwlines))
+
+    try:
+      style.SetGlobalStyle(
+          style.CreateStyleFromConfig(
+              '{based_on_style: pep8, '
+              'blank_line_before_module_docstring: True}'))
+      unformatted_code = textwrap.dedent('''\
+        #!/usr/bin/env python
+        # -*- coding: utf-8 name> -*-
+        """Some module docstring."""
+
+
+        def foobar():
+            pass
+          ''')
+      expected_formatted_code = textwrap.dedent('''\
+        #!/usr/bin/env python
+        # -*- coding: utf-8 name> -*-
+
+        """Some module docstring."""
+
+
+        def foobar():
+            pass
+          ''')
+      uwlines = yapf_test_helper.ParseAndUnwrap(unformatted_code)
+      self.assertCodeEqual(expected_formatted_code,
+                           reformatter.Reformat(uwlines))
+    finally:
+      style.SetGlobalStyle(style.CreateChromiumStyle())
+
   def testTupleCohesion(self):
     unformatted_code = textwrap.dedent("""\
         def f():

Space between modeline/shebang and module docstring
Imagine this file:

``` python
#!/usr/bin/env python
# -*- coding: utf-8 name> -*-

"""Some module docstring."""


def foobar():
    pass
```

Running yapf on it produces this diff:

``` diff
--- yapf.py (original)
+++ yapf.py (reformatted)
@@ -1,6 +1,5 @@
 #!/usr/bin/env python
 # -*- coding: utf-8 name> -*-
-
 """Some module docstring."""

```

I would actually have expected yapf **not** to remove the blank line between the shebang/encoding and the module docstring (i.e. do nothing).

yapftests/reformatter_basic_test.py::BasicReformatterTest::testBlankLineBeforeModuleDocstring
yapftests/reformatter_basic_test.py::BasicReformatterTest::testArgsAndKwargsFormatting yapftests/reformatter_basic_test.py::BasicReformatterTest::testBinaryOperators yapftests/reformatter_basic_test.py::BasicReformatterTest::testBlankLineBeforeClassDocstring yapftests/reformatter_basic_test.py::BasicReformatterTest::testBlankLinesAtEndOfFile yapftests/reformatter_basic_test.py::BasicReformatterTest::testBlankLinesBeforeDecorators yapftests/reformatter_basic_test.py::BasicReformatterTest::testBlankLinesBeforeFunctionsNotInColumnZero yapftests/reformatter_basic_test.py::BasicReformatterTest::testClosingBracketIndent yapftests/reformatter_basic_test.py::BasicReformatterTest::testClosingBracketsInlinedInCall yapftests/reformatter_basic_test.py::BasicReformatterTest::testCoalesceBracketsOnDict yapftests/reformatter_basic_test.py::BasicReformatterTest::testCommentBeforeFuncDef yapftests/reformatter_basic_test.py::BasicReformatterTest::testCommentBetweenDecorators yapftests/reformatter_basic_test.py::BasicReformatterTest::testCommentColumnLimitOverflow yapftests/reformatter_basic_test.py::BasicReformatterTest::testComments yapftests/reformatter_basic_test.py::BasicReformatterTest::testCommentsInDataLiteral yapftests/reformatter_basic_test.py::BasicReformatterTest::testCommentsWithContinuationMarkers yapftests/reformatter_basic_test.py::BasicReformatterTest::testCommentsWithTrailingSpaces yapftests/reformatter_basic_test.py::BasicReformatterTest::testComprehensionForAndIf yapftests/reformatter_basic_test.py::BasicReformatterTest::testContiguousList yapftests/reformatter_basic_test.py::BasicReformatterTest::testContinuationIndent yapftests/reformatter_basic_test.py::BasicReformatterTest::testContinuationMarkerAfterStringWithContinuation yapftests/reformatter_basic_test.py::BasicReformatterTest::testContinuationMarkers yapftests/reformatter_basic_test.py::BasicReformatterTest::testContinuationSpaceRetention yapftests/reformatter_basic_test.py::BasicReformatterTest::testDictSetGenerator yapftests/reformatter_basic_test.py::BasicReformatterTest::testDictionaryElementsOnOneLine yapftests/reformatter_basic_test.py::BasicReformatterTest::testDictionaryMakerFormatting yapftests/reformatter_basic_test.py::BasicReformatterTest::testDictionaryOnOwnLine yapftests/reformatter_basic_test.py::BasicReformatterTest::testDictionaryValuesOnOwnLines yapftests/reformatter_basic_test.py::BasicReformatterTest::testDocstringAndMultilineComment yapftests/reformatter_basic_test.py::BasicReformatterTest::testDocstrings yapftests/reformatter_basic_test.py::BasicReformatterTest::testDontAddBlankLineAfterMultilineString yapftests/reformatter_basic_test.py::BasicReformatterTest::testDontSplitKeywordValueArguments yapftests/reformatter_basic_test.py::BasicReformatterTest::testEllipses yapftests/reformatter_basic_test.py::BasicReformatterTest::testEmptyContainers yapftests/reformatter_basic_test.py::BasicReformatterTest::testEndingComment yapftests/reformatter_basic_test.py::BasicReformatterTest::testEndingWhitespaceAfterSimpleStatement yapftests/reformatter_basic_test.py::BasicReformatterTest::testExcessCharacters yapftests/reformatter_basic_test.py::BasicReformatterTest::testExcessLineCountWithDefaultKeywords yapftests/reformatter_basic_test.py::BasicReformatterTest::testExpressionPenalties yapftests/reformatter_basic_test.py::BasicReformatterTest::testFormattingListComprehensions yapftests/reformatter_basic_test.py::BasicReformatterTest::testFunctionCallArguments yapftests/reformatter_basic_test.py::BasicReformatterTest::testFunctionCallContinuationLine yapftests/reformatter_basic_test.py::BasicReformatterTest::testFunctionCallInDict yapftests/reformatter_basic_test.py::BasicReformatterTest::testFunctionCallInNestedDict yapftests/reformatter_basic_test.py::BasicReformatterTest::testI18n yapftests/reformatter_basic_test.py::BasicReformatterTest::testI18nCommentsInDataLiteral yapftests/reformatter_basic_test.py::BasicReformatterTest::testI18nNonFormatting yapftests/reformatter_basic_test.py::BasicReformatterTest::testIfConditionalParens yapftests/reformatter_basic_test.py::BasicReformatterTest::testIfExpressionWithFunctionCall yapftests/reformatter_basic_test.py::BasicReformatterTest::testImportAsList yapftests/reformatter_basic_test.py::BasicReformatterTest::testLineDepthOfSingleLineStatement yapftests/reformatter_basic_test.py::BasicReformatterTest::testLineWrapInForExpression yapftests/reformatter_basic_test.py::BasicReformatterTest::testListComprehension yapftests/reformatter_basic_test.py::BasicReformatterTest::testListComprehensionPreferNoBreakForTrivialExpression yapftests/reformatter_basic_test.py::BasicReformatterTest::testListComprehensionPreferOneLine yapftests/reformatter_basic_test.py::BasicReformatterTest::testListComprehensionPreferOneLineOverArithmeticSplit yapftests/reformatter_basic_test.py::BasicReformatterTest::testListComprehensionPreferThreeLinesForLineWrap yapftests/reformatter_basic_test.py::BasicReformatterTest::testListWithFunctionCalls yapftests/reformatter_basic_test.py::BasicReformatterTest::testMatchingParenSplittingMatching yapftests/reformatter_basic_test.py::BasicReformatterTest::testMultilineComment yapftests/reformatter_basic_test.py::BasicReformatterTest::testMultilineCommentReformatted yapftests/reformatter_basic_test.py::BasicReformatterTest::testMultilineDictionaryKeys yapftests/reformatter_basic_test.py::BasicReformatterTest::testMultilineDocstringAndMultilineComment yapftests/reformatter_basic_test.py::BasicReformatterTest::testMultilineLambdas yapftests/reformatter_basic_test.py::BasicReformatterTest::testMultilineShebang yapftests/reformatter_basic_test.py::BasicReformatterTest::testMultilineString yapftests/reformatter_basic_test.py::BasicReformatterTest::testMultipleContinuationMarkers yapftests/reformatter_basic_test.py::BasicReformatterTest::testMultipleUgliness yapftests/reformatter_basic_test.py::BasicReformatterTest::testNamedAssignNotAtEndOfLine yapftests/reformatter_basic_test.py::BasicReformatterTest::testNestedDictionary yapftests/reformatter_basic_test.py::BasicReformatterTest::testNestedListsInDictionary yapftests/reformatter_basic_test.py::BasicReformatterTest::testNoBreakOutsideOfBracket yapftests/reformatter_basic_test.py::BasicReformatterTest::testNoKeywordArgumentBreakage yapftests/reformatter_basic_test.py::BasicReformatterTest::testNoPenaltySplitting yapftests/reformatter_basic_test.py::BasicReformatterTest::testNoQueueSeletionInMiddleOfLine yapftests/reformatter_basic_test.py::BasicReformatterTest::testNoSpaceBetweenUnaryOpAndOpeningParen yapftests/reformatter_basic_test.py::BasicReformatterTest::testNoSpacesAroundKeywordDefaultValues yapftests/reformatter_basic_test.py::BasicReformatterTest::testNoSpacesBetweenOpeningBracketAndStartingOperator yapftests/reformatter_basic_test.py::BasicReformatterTest::testNoSpacesBetweenSubscriptsAndCalls yapftests/reformatter_basic_test.py::BasicReformatterTest::testNoSplittingAroundTermOperators yapftests/reformatter_basic_test.py::BasicReformatterTest::testNoSplittingBeforeEndingSubscriptBracket yapftests/reformatter_basic_test.py::BasicReformatterTest::testNoSplittingOnSingleArgument yapftests/reformatter_basic_test.py::BasicReformatterTest::testNoSplittingWhenBinPacking yapftests/reformatter_basic_test.py::BasicReformatterTest::testNoSplittingWithinSubscriptList yapftests/reformatter_basic_test.py::BasicReformatterTest::testNotInParams yapftests/reformatter_basic_test.py::BasicReformatterTest::testNotSplittingAfterSubscript yapftests/reformatter_basic_test.py::BasicReformatterTest::testOpeningAndClosingBrackets yapftests/reformatter_basic_test.py::BasicReformatterTest::testOverColumnLimit yapftests/reformatter_basic_test.py::BasicReformatterTest::testRelativeImportStatements yapftests/reformatter_basic_test.py::BasicReformatterTest::testRelaxArraySubscriptAffinity yapftests/reformatter_basic_test.py::BasicReformatterTest::testSimple yapftests/reformatter_basic_test.py::BasicReformatterTest::testSimpleFunctions yapftests/reformatter_basic_test.py::BasicReformatterTest::testSimpleFunctionsWithTrailingComments yapftests/reformatter_basic_test.py::BasicReformatterTest::testSimpleMultilineCode yapftests/reformatter_basic_test.py::BasicReformatterTest::testSimpleMultilineWithComments yapftests/reformatter_basic_test.py::BasicReformatterTest::testSingleComment yapftests/reformatter_basic_test.py::BasicReformatterTest::testSingleLineFunctions yapftests/reformatter_basic_test.py::BasicReformatterTest::testSingleLineList yapftests/reformatter_basic_test.py::BasicReformatterTest::testSpaceAfterNotOperator yapftests/reformatter_basic_test.py::BasicReformatterTest::testSplitAfterComment yapftests/reformatter_basic_test.py::BasicReformatterTest::testSplitListWithComment yapftests/reformatter_basic_test.py::BasicReformatterTest::testSplitListWithInterspersedComments yapftests/reformatter_basic_test.py::BasicReformatterTest::testSplitListWithTerminatingComma yapftests/reformatter_basic_test.py::BasicReformatterTest::testSplitStringsIfSurroundedByParens yapftests/reformatter_basic_test.py::BasicReformatterTest::testSplittingArgumentsTerminatedByComma yapftests/reformatter_basic_test.py::BasicReformatterTest::testSplittingArraysSensibly yapftests/reformatter_basic_test.py::BasicReformatterTest::testSplittingBeforeFirstArgumentOnCompoundStatement yapftests/reformatter_basic_test.py::BasicReformatterTest::testSplittingBeforeFirstArgumentOnFunctionCall yapftests/reformatter_basic_test.py::BasicReformatterTest::testSplittingBeforeFirstArgumentOnFunctionDefinition yapftests/reformatter_basic_test.py::BasicReformatterTest::testSplittingBeforeFirstElementListArgument yapftests/reformatter_basic_test.py::BasicReformatterTest::testSplittingOneArgumentList yapftests/reformatter_basic_test.py::BasicReformatterTest::testStableDictionaryFormatting yapftests/reformatter_basic_test.py::BasicReformatterTest::testStableInlinedDictionaryFormatting yapftests/reformatter_basic_test.py::BasicReformatterTest::testSubscriptExpression yapftests/reformatter_basic_test.py::BasicReformatterTest::testTrailerOnSingleLine yapftests/reformatter_basic_test.py::BasicReformatterTest::testTrailingCommaAndBracket yapftests/reformatter_basic_test.py::BasicReformatterTest::testTupleCohesion yapftests/reformatter_basic_test.py::BasicReformatterTest::testTupleCommaBeforeLastParen yapftests/reformatter_basic_test.py::BasicReformatterTest::testUnaryNotOperator yapftests/reformatter_basic_test.py::BasicReformatterTest::testUnaryOpInDictionaryValue yapftests/reformatter_basic_test.py::BasicReformatterTest::testUnbreakableNot yapftests/reformatter_basic_test.py::BasicReformatterTest::testUnformattedAfterMultilineString