Is there a way to create an enum in a vyper file ?

I have tried this:

from enum import Enum

But it does not work

Any idea ?



2 Answers 2


Enums were added to Vyper. Not sure when, but it's in v0.3.7. Example:

# _Defining an enum with two members
enum Roles:

# Declaring an enum variable
role: Roles = Roles.ADMIN

# Returning a member
return Roles.ADMIN

Full details at readthedocs.


There is no native enum type in Vyper, so you'll have to construct your own.

Others may have better ideas, but you could either use:

...but you'll have to consider the gas costs of each.

The best alternative is probably to architect your contract in such a way as to avoid needing enums.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.