7

I am looking for some Python library similar to Java's Lombok. I found puffadder 0.1, from 2016, but now that I tried to install it with pip, it does not work.

Links:

Shell output:

$ pip3 install puffadder
Collecting puffadder
  Could not find a version that satisfies the requirement puffadder (from versions: )
No matching distribution found for puffadder

$ pip --version
pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)

$ pip3 --version
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)

$ pip3 install puffadder==0.1
Collecting puffadder==0.1
  Could not find a version that satisfies the requirement puffadder==0.1 (from versions: )
No matching distribution found for puffadder==0.1

$ pip install puffadder==0.1
Collecting puffadder==0.1
  Could not find a version that satisfies the requirement puffadder==0.1 (from versions: )
No matching distribution found for puffadder==0.1

$ sudo lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.3 LTS
Release:    18.04
Codename:   bionic

So, is it not compatible anymore with modern versions of Python? Why is not in pip anymore, was it discontinued, or just lack of integration in pip (so, I could maybe clone it from GitHub).

Also, does someone know some supported alternative, apart from using @property?

xCovelus
  • 578
  • 1
  • 9
  • 20

2 Answers2

11

Python 3.7 added dataclasses Which reminds me of the Lombok in Java. It generates _init_, _repr_ and some more.

from dataclasses import dataclass

@dataclass()
class Name:
    first_name: str
    last_name: str

yoni = Name("Yoni", "Alaluf")
yoni2 = Name("Jony", "Alaluf")
print(yoni) # Name(first_name='Yoni', last_name='Alaluf')
print(yoni2) # Name(first_name='Jony', last_name='Alaluf')
print(yoni == yoni2) # False

Paulo
  • 1,458
  • 2
  • 12
  • 26
Yoni
  • 375
  • 3
  • 19
  • 1
    but , what about other Lombok's features like NotNull etc ? – DukeLover Oct 05 '21 at 06:36
  • 1
    clearly @dukelover, this isn't including all Lombok features, though if you wont supply one of the properties you will get an error, e.g if you will try to create `Name('Yoni')` you will get an init error `n = Name('yoni') TypeError: __init__() missing 1 required positional argument: 'last_name'` There are several tweaks you can probably use with the [field method](https://docs.python.org/3.8/library/dataclasses.html#dataclasses.field) – Yoni Oct 06 '21 at 17:24
  • 3
    Note the reader, you may be interested by the Paprika project (inspired by lombok). Visit the project: https://pythonrepo.com/repo/rayanht-paprika – Stephan Feb 03 '22 at 10:48
2

Try python library Paprika.

https://github.com/rayanht/paprika

It will give handy annotations to reduce the code.

Arslan Arshad
  • 31
  • 1
  • 4