puffadder icon indicating copy to clipboard operation
puffadder copied to clipboard

A boiler plate reducing library for Python, inspired by Project Lombok for Java.

puffadder

A boiler plate reducing library for Python, inspired by Project Lombok for Java.

@to_string

Adds a str function to the class that returns all public instance attributes in a neatly formatted string.

Puffadder Vanilla Python
@to_string
class Student(object):
  _private_attribute = "This will not be seen"
  name = "Sally"
  age = 22
  full_time = True

john = Student() john.name = "John" print(Student()) {name=John, age=22, full_time=True}

class Student(object):
  _private_attribute = "This will not be seen"
  name = "Sally"
  age = 22
  full_time = True

def str(self): return "{{name={}, age={}, full_time={}}}" .format(self.name, self.age, self.ful_time)

john = Student() john.name = "John" print(Student()) {name=John, age=22, full_time=True}

@builder

Adds a constructor to the class that sets all public class attributes in the constructor. If a constructor was defined it is run after the generated constructor.

Puffadder Vanilla Python
@builder
class Student(object):
  _private_attribute = "This will not be seen"
  name = "Sally"
  age = 22
  full_time = True

john = Student( name="John", age=30, full_time=False )

class Student(object):
  def __init__(self, name="Sally", age=22, full_time=True):
    self.name = name
    self.age = age
    self.full_time = full_time
    self._private_attribute = "This will not be seen"

john = Student( name="John", age=30, full_time=False )

@constructor

Adds all parameters defined in the constructor to the class's properties. If a constructor was defined it is run after the generated constructor.

Puffadder Vanilla Python
@contructor
class Student(object):
  def __init__(self, name, age=22, full_time=True):
    self._private_attribute = "private"

john = Student( name="John", age=30, full_time=False )

class Student(object):
  def __init__(self, name, age=22, full_time=True):
    self.name = name
    self.age = age
    self.full_time = full_time
    self._private_attribute = "private"

john = Student( name="John", age=30, full_time=False )