Skip to content

Python module

A blueprint that creates a Python module folder with __init__.py, the module itself and a pytest test. Python module names are written in snake_case, so the file names use {name.snake}.

blueprintor.config.js
module.exports = {
blueprints: [
{
title: "Python module",
variables: [{ key: "name", prompt: "Module name" }],
snippets: {
init: `
from .{name.snake} import {name.pascal}
__all__ = ["{name.pascal}"]
`,
module: `
"""{name.raw}."""
class {name.pascal}:
"""{name.raw}."""
def __init__(self) -> None:
pass
`,
test: `
from .{name.snake} import {name.pascal}
def test_{name.snake}_can_be_created():
assert {name.pascal}() is not None
`,
},
structure: {
folders: [
{
name: "{name.snake}",
files: [
{ name: "__init__.py", snippet: "init" },
{ name: "{name.snake}.py", snippet: "module" },
{ name: "test_{name.snake}.py", snippet: "test" },
],
},
],
},
},
],
};
  1. Right-click the folder where the module should live (for example src) and choose Run Blueprintor….

  2. Select Python module.

  3. Enter my idea. The same folder would be created for my-idea, my_idea or MyIdea.

  • Directorysrc
    • Directorymy_idea
      • __init__.py
      • my_idea.py
      • test_my_idea.py
from .my_idea import MyIdea
__all__ = ["MyIdea"]

The three forms are used for different jobs: {name.snake} for module and file names, {name.pascal} for the class, {name.raw} for the human-readable text in docstrings.