Naively I try
from decimal cimport Decimal
cpdef Decimal to_decimal(str value):
return Decimal(value)
However when I try to compile this I get the following error
Error compiling Cython file:
------------------------------------------------------------
...
from decimal cimport Decimal
^
------------------------------------------------------------
helloworld.pyx:1:0: 'decimal.pxd' not found
Error compiling Cython file:
------------------------------------------------------------
...
from decimal cimport Decimal
^
------------------------------------------------------------
helloworld.pyx:1:0: 'decimal/Decimal.pxd' not found
Error compiling Cython file:
------------------------------------------------------------
...
from decimal cimport Decimal
cpdef Decimal to_decimal(str value):
^
------------------------------------------------------------
helloworld.pyx:3:6: 'Decimal' is not a type identifier
Error compiling Cython file:
------------------------------------------------------------
...
from decimal cimport Decimal
cpdef Decimal to_decimal(str value):
return Decimal(value)
^
------------------------------------------------------------
helloworld.pyx:4:11: 'Decimal' is not a constant, variable or function identifier
I know the Decimal class is created from this c extension file https://github.com/python/cpython/blob/master/Modules/_decimal/_decimal.c. So it seems like it should be usable in cython code. Anyone know how?