<p>It's almost certainly possible to do, but depending on how far down you want to go, you will need to write some parts in another language. The authors of <a href="https://arxiv.org/pdf/1901.10664.pdf" rel="nofollow noreferrer">this paper</a> [1] wrote a version of their user-space network driver <a href="https://github.com/ixy-languages/ixy-languages" rel="nofollow noreferrer">in Python</a>, but they used Cython for external memory management.</p>

<p>While using Python for this is probably possible, Python is much slower than many other languages. The authors of the paper I mentioned <a href="https://github.com/ixy-languages/ixy-languages" rel="nofollow noreferrer">implemented their driver in 10 languages and compared them</a>, and Python was the slowest—10 times slower than the next-slowest (but they do note (in [2]) that all of their drivers <em>except</em> the Python driver were optimized for performance).</p>

<p>Generally speaking, if you want to learn how to do systems programming, I recommend doing it in a systems language, like C or Rust. Traditionally, this type of code would most-often be written in C. If you want arguments in favor of using languages besides C, the same authors wrote <a href="https://www.net.in.tum.de/fileadmin/bibtex/publications/papers/the-case-for-writing-network-drivers-in-high-level-languages.pdf" rel="nofollow noreferrer">this paper</a> [2], which discusses why you would want to use higher-level languages (from Rust to Python) for writing a network driver.</p>

<p>In short, Python probably isn't the best language for this if you want it to be more than a toy project, but if you want to do it, the Python code from those papers is probably a good place to start on the lowest-level parts; in fact, the authors hoped to be helpful to others [2]:</p>

<blockquote>
  <p>We provide primitives for PCIe driver development in Python that we hope to be helpful to others as this is the first PCIe driver in Python to our knowledge.</p>
</blockquote>

<hr>



<ol>
<li><p>P. Emmerich, M. Pudelko, S. Bauer, S. Huber, T. Zwickl, and G. Carle,
"User Space Network Drivers,"
in ACM/IEEE Symposium on Architectures for Networking and Communications Systems (ANCS 2019), 2019.
<a href="https://arxiv.org/abs/1901.10664" rel="nofollow noreferrer">arXiv:1901.10664</a> [cs.NI]</p></li>
<li><p>P. Emmerich, S. Ellmann, F. Bonk, A. Egger, E. G. Sánchez-Torija, T. Günzel, S. Di Luzio, A. Obada, M. Stadlmeier, S. Volt, and G. Carle,
"The Case for Writing Network Drivers in High-Level Programming Languages,"
in ANCS 2019.
<a href="https://arxiv.org/abs/1909.06344" rel="nofollow noreferrer">arXiv:1909.06344</a> [cs.NI]</p></li>
</ol>
Is it possible to create a userspace networking stack with python?
<p>Looking to create a project which implements a <em>user-space networking stack</em>, so that a user space application has access to the network cards, I've never done this before and I was wondering if it would possible to get this close to the hardware using a language like <em>python</em> and, if not, which language would be best?</p>