Welcome! This site is currently in beta. Get 10% off everything with promo code BETA10.

Blog Post

How to Use Sublime Text for Python Web Development

10 min to complete · By CodingNomads Team

This article was originally published on Medium.com.

Sublime Text’s rich package ecosystem makes it possible to fine-tune the text editor specifically to what you are using it for. Some of the packages are universally helpful, others, such as syntax checking, are specific to the programming language you are working with.

Changing settings is easy and might also help to clarify how to do further customizations — if that is where your ❤ is at.

Keep reading below for step-by-step guidance on how to use Sublime Text for Python.

Sublime Settings

Before moving onto installing plugins, there are a couple of useful settings that can help to tailor your Sublime Text for Python development. Go to Sublime Text → Preferences → Settings and in the Preferences.sublime.settings-User file enter the following rules:

{ "spell_check": false, "rulers": [ 72, 79 ], "tab_size": 4, "translate_tabs_to_spaces": true, "trim_trailing_white_space_on_save": true, "ensure_newline_at_eof_on_save": true }

I personally prefer to keep “spell_check” on false because I don’t like to see red lines everywhere when writing non-dictionary-compliant words. Maybe I’m just damaged by the school system. If you have a different opinion on this, simply set “spell_check” to true.

The magic numbers for the “rulers” setting originate from pythons PEP8. Docstrings and comments should be limited to 72 characters and all other lines should not be longer than 79 characters. The ruler lines can help to remind you when you are approaching these limits.

In good Python fashion we set the “tab_size” to 4 and “translate_tabs_to_spaces” to avoid relationship troubles.

Finally, we can get another PEP8 compliance automation with “ensure_newline_at_eof_on_save” which does just that: adding a single newline at the end of the file when you save the document.

Sublime Text for Python Packages (Plugins)

The next step for how to use Sublime Text for Python is to dive into the pool of great packages for Sublime Text. These packages extend its functionality and can make your life as a programmer easier – and more colorful!

SidebarEnhancement

Power-up for the ST sidebar, introducing useful features such as being able to create new files directly from there and sending files to the recycle bin when they are deleted from inside Sublime.

Anaconda

Note: this is not the popular python distribution often used for data science that goes by the same name.

The Sublime Text Anaconda plugin helps to make ST more IDE-like while keeping it still operating much quicker than most IDEs. It introduces easy access to useful features such as:

  • Code autocompletion
  • Code linting: syntax errors
  • Code linting: highlight and automatically fix PEP8 violations
  • Python documentation on class, method or function under the cursor
  • Goto Python definition anywhere in the project
  • Find object usage across the project
  • and lots more…

Auto Docstring

Auto Docstring does just what its name suggests — it allows you to swiftly create a Python docstring template for your selected function, method or class. You can even add docstrings for every function in a file and change between Google and Numpy style even after the docstrings were created. A very basic auto-generated example would look like this:

def my_function(): """Summary

Returns:
    TYPE: Description
"""
return None

SublimeLinter

For Python syntax and PEP8 you could stick with using the linting provided through the Anaconda plugin. However, using SublimeLinter has the advantage that it is extensible also with other linters that are useful for web development. That’s why I would suggest to disable Anaconda’s linter, like so:

Use the file menu: Sublime → Preferences → Package Settings → Anaconda → Settings — User to go to the user-defined Anaconda settings file. Then set: {"anaconda_linting": false}

Now, install SublimeLinter using the Package Manager.

Note: Most of the linters require additional packages to operate correctly, so make sure to read the instructions carefully

SublimeLinter-pyflakes

pyflakes performs syntax checking on python files. This package needs to be installed using pip before adding it to ST with the Package Manager

SublimeLinter-pycodestyle

pycodestyle is the new name of the pep8 package. Install it using pip, then add it to Sublime using the Package Manager for PEP8-compliant code style linting.

Other useful linters for web development:

Djaneiro

This useful plugin adds a couple of handy Django snippets with tab autocompletion into ST to make working on web projects quicker.

E.g. block + TAB generates {% block %}{% endblock %}

Very cool. Check out all it has to offer here!

Git

Allows to do the most common set of git commands from within Sublime Text.
git add, commit, push etc. right from your favorite text editor.

GitGutter

GitGutter helps to keep track of which files have been edited since the last commit. It adds small symbols next to the line numbers that indicate their status in relation to the git repository.

requirementstxt

Introduces syntax highlighting for requirements.txt files. Be good to your 👀!

Markdown Preview

Allows to preview Markdown documents in your browser — build them using different available flavors!

Other useful Web Dev Packages

CSS3

The CSS3 plugin allows for futuristic CSS syntax highlighting. You’ll need to tweak the rest of the settings a bit, but it’s easy to follow along the steps on the site linked above.

ColorHighlighter

This one is fun. Adds more 🌈 to your code. Hex color values will be displayed with the corresponding color as background. Makes it easier to remember what color you were adding where.

Emmet

If you’re excited about automating the repetitive parts of your web development work, then Emmet can be a big help. Install the package, then learn how to benefit: https://docs.emmet.io/cheat-sheet/

More info on how to use Sublime Text for Python:

Plugin Setup:

Learn to increase your performance when working with ST3:

If you’re interested to learn about other Python IDEs:

Wrapping Up

There you have it, you now have a comprehensive guide for getting started on how to use Sublime Text for Python. With adding these packages and tweaking the settings as mentioned above, Sublime Text becomes a lightweight but powerful editor for web development.