title: How to declare enum in Cython pxd file for interface with external C library?
body: <p>I'm trying to use Cython to call external C library from Python. The code looks like this:</p>
  <p>header.h</p>
  <pre class="lang-h prettyprint-override"><code>typedef enum {
      A = 0,
      B = 1,
      C = 2,
      D = 3
  } my_enum_type;
  </code></pre>
  <p>cheader.pxd</p>
  <pre class="lang-cython prettyprint-override"><code>cdef extern from &quot;header.h&quot;:
      ctypedef enum my_enum_type:
          A = 1,
          B = 2,
          C = 3,
          D = 4
  </code></pre>
  <p>code.pyx</p>
  <pre class="lang-cython prettyprint-override"><code>cimport cheader
  
  cdef cheader.my_enum_type test = A
  
  if test == A:
      print(&quot;OK&quot;)
  else:
      print(&quot;NOK&quot;)
  </code></pre>
  <p>With code above I get compiler error: <strong>undeclared name not builtin: A</strong></p>
  <p>With code bellow there are no compilation errors.</p>
  <pre class="lang-cython prettyprint-override"><code>cimport cheader
  
  cdef cheader.my_enum_type test = cheader.my_enum_type.A
  
  if test == cheader.my_enum_type.A:
      print(&quot;OK&quot;)
  else:
      print(&quot;NOK&quot;)
  </code></pre>
  <p>If enum is defined in pyx file than code bellow can be used:</p>
  <pre class="lang-cython prettyprint-override"><code>ctypedef enum my_enum_type:
      A = 1,
      B = 2,
      C = 3,
      D = 4
  
  cdef my_enum_type test = A
  
  if test == A:
      print(&quot;OK&quot;)
  else:
      print(&quot;NOK&quot;)
  </code></pre>
  <p>Is it possible to declare enum in pxd file so it's not necessary to reference imported module every time enum has to be used?</p>
  <p>What is the proper way to declare enum in pxd file and use it in pyx files?</p>