# Include typing file with C extension

**URL:** <https://discuss.python.org/t/include-typing-file-with-c-extension/24188>\
**Category:** Packaging\
**Created:** [February 23, 2023, 7:46pm UTC](https://discuss.python.org/t/include-typing-file-with-c-extension/24188 "2023-02-23T19:46:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Safihre](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/safihre/32/6574_2.png) [@Safihre](https://discuss.python.org/u/Safihre)\
**Post date:** [February 23, 2023, 7:46pm UTC](https://discuss.python.org/t/include-typing-file-with-c-extension/24188/1 "2023-02-23T19:46:58Z")

</div>

Due to a quite complex build, we use setuptools to build our C extension `sabctools`.  
I wanted to distribute a `sabctools.pyi` file with it for typing information. but I got stuck:  
When the wheel is installed it puts the `sabctools.pyd` (or `.so`, depende on platform) file in the main `site-packages` directory, so only when `sabctools.pyi` is in the same directory, it’s picked up by PyCharm etc as the valid typing file for the extension.  
But I didn’t find a way to get pip to place the `sabctools.pyi` file in that directory.  
Mostly I get the feeling this probably not how I should be making the wheel? Should the `sabctools.pyd` file be in a separate `sabctools` folder in `site-packages` which then can include the `sabctools.pyi`?  
Our setup.py, for reference: [sabctools/setup.py at master · sabnzbd/sabctools · GitHub](https://github.com/sabnzbd/sabctools/blob/master/setup.py#L345-L359)

---

<div class="post-metadata">

**Author:** ![merwok](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/merwok/32/29_2.png) [@merwok](https://discuss.python.org/u/merwok)\
**Post date:** [February 23, 2023, 8:07pm UTC](https://discuss.python.org/t/include-typing-file-with-c-extension/24188/2 "2023-02-23T20:07:26Z")

</div>

You should be able to make a little change to your extension module so that it’s built as a submodule of a package (a module with submodules, implemented by a directory containing ` __init__.py` file), have the `sabctools.pyi` and `py.typed` files next to the extension module, and tell setuptools to package the whole package and its package data.

---

<div class="post-metadata">

**Author:** ![Safihre](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/safihre/32/6574_2.png) [@Safihre](https://discuss.python.org/u/Safihre)\
**Post date:** [February 24, 2023, 7:15am UTC](https://discuss.python.org/t/include-typing-file-with-c-extension/24188/3 "2023-02-24T07:15:50Z")

</div>

That worked indeed. Is that how a C extension is supposed to be configured from the start?

---

<div class="post-metadata">

**Author:** ![CAM-Gerlach](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/cam-gerlach/32/3688_2.png) [@CAM-Gerlach](https://discuss.python.org/u/CAM-Gerlach)\
**Post date:** [February 24, 2023, 8:48am UTC](https://discuss.python.org/t/include-typing-file-with-c-extension/24188/4 "2023-02-24T08:48:19Z")

</div>

Unless I’m mistaken, this situation is essentially the same for any Python distribution artifact, pure or C extension. AFAIK, distributions that contain a top-level module cannot bundle a `py.typed` file or type stubs (or other non-importable assets) as there’s nowhere unambiguous to put them—they have to be an import packages for that (same with certain other limitations). It’s arguably a good idea to just make things import packages from the start, as it saves the pain of switching and providing backward compat if you end up needing any of that later.
