Skip to content

Code style guide

This guide includes information and guidelines for writing code for BeeWare.

Code style

BeeWare follows PEP 8 in our codebase, except with the line length expanded from 79 to 88 characters. We use Ruff to enforce PEP 8 conventions where possible. When you commit your code, pre-commit will run checks, including Ruff. Where possible, this will autoformat your code to ensure it meets our formatting and style standards. You can set up some IDEs to automatically run Ruff on save, which can help with the process.

Keep in mind that the most important part of PEP 8 is Section 0: A Foolish Consistency is the Hobgoblin of Little Minds. There are situations where remaining consistent with PEP 8 doesn't make sense, and it is important to understand that, when applicable, it is acceptable, and sometimes preferred, to write code that isn't in line with the rules listed. Knowing when to be inconsistent with those rules is as important as maintaining consistency in most situations.

We follow US spelling for API naming, variables, etc.

Things to avoid

We try to avoid utils modules as much as possible, with the understanding that sometimes they are unavoidable. The preferred alternative is to find somewhere for the feature elsewhere in the source code, instead of using a utils module.

As a general rule, we try to avoid or defer any expensive initialization code, in order to achieve faster app startup. For instance, modules in the toga-core package are "lazy loaded" — they're only imported once requested, rather than all up front. This speeds up startup, and only spends time on what the app is actually using.