nx-python: Create Python Homebrew for the Switch!

HlzR.jpeg

nx-python
is an ecosystem for developing and running Python homebrew applications on the Nintendo Switch. PyNX serves as the entry point to this ecosystem and allows you to run Python apps on your Switch. It is a homebrew app that contains a port of the CPython interpreter and allows you to run Python applications from the Homebrew Menu. Just name your application main.py and place it next to the PyNX.nro, and it will be executed as soon as you launch PyNX from the Homebrew Menu. Simply grab a release build and copy the content of the ZIP archive into the /switch folder on your SD card. PyNX will appear on the Homebrew Menu. Currently, Python 3.5 is supported. Basic things should work fine, but for many advanced things, like PyGame, you will have to wait a bit until they are supported. This also includes threading, as well as the signal module. Those are high priority, though, so you won't have to wait for them for too long, hopefully. For Switch-specific things, such as controller input or filesystem read/write, you can use the nx package that's included in PyNX (see documentation).

I hope nx-python will allow many more people to develop awesome homebrew applications for the Switch. :)

If you encounter a problem, make sure to join our Discord and tell us about it, or, alternatively, reply to this thread.

Quick links: Download | Documentation | Discord | Source

Special thanks to DavidBuchanan314, @MarcusD, @Stary2001, rami, and several other people from ReSwitched as well as the SwitchBrew team, the devkitPro team, and the Python Software Foundation.
 
Last edited by AileenLumina,
OwO what's this?

In all seriousness this is awesome and I will definitely be using this
Thank you! ^-^
Now that Python works.. can we have Ren'Py next ? :D

Was just going to say this. But that needs Python 2.7 and a dozen dependecneis.
Can't you just import the old libraries (whatever the opposite of importing from _future_ is) and put all the dependencies in the same folder as the main .py?
Unfortunately, if Ren'Py only supports Py2.7, we're gonna have a problem. That would require some porting effort, unfortunately. :/
Before we fantasize about Ren'Py, they should implement more basic things like "numpy". I need my multi-dimensional arrays. :D

Btw, great work. One suggestion: Please add a text editor which utilizes the onscreen keyboard (or a bluetooth keyboard), so we can write applications on the go.
Planned and planned! :D
Is there a plan to add support for yuzu? I don't have a 3.0.0 switch and it would be nice to create homebrew before cfw comes to older fws.
We were working with the RyujiNX devs to add support for Pynx. RyujiNX supports Pynx now. :)

I'm happy about the great response nx-python gets! Thank you, guys! ^-^
 
We just started implementing Switch-specific functions! You can now let your users use the hardware buttons to interact with your program. :) (This is not very pythonic yet, I'm working on that right now. ^^)
Question: will there be a Switch-specific graphics library, or will we have to use our own? And as an extension, if we decide to use our own and, for example, the library has a function to grab keyboard keystrokes/mouse clicks, could that be adapted to button presses and screen touches relatively easily?
 
@TotalInsanity4 I do want to port SDL/SDL2, OpenGL and Vulkan. I'm not sure if we will, though. Do expect PyGameNX to happen, though. :)

Edit: Adding support for buttons and the touchscreen won't be hard at all, really. Either you use the low-level libnx bindings, or you use what the high-level nx package provides you with.
 
Last edited by AileenLumina,
>>> import _nx
>>> _nx.account_initialize()
>>> uid = _nx.account_get_active_user()
>>> _nx.fs_mount_savedata("save", 0x01007ef00011e000, uid)
>>> os.listdir("save:/")
['pict_book', 'album', '5', '4', '3', '2', '1', 'tracker', '0', 'option.sav']


Remote REPL and savedata access! \o/
 
>>> import _nx
>>> _nx.account_initialize()
>>> uid = _nx.account_get_active_user()
>>> _nx.fs_mount_savedata("save", 0x01007ef00011e000, uid)
>>> os.listdir("save:/")
['pict_book', 'album', '5', '4', '3', '2', '1', 'tracker', '0', 'option.sav']


Remote REPL and savedata access! \o/
Oh hey now that we're getting Switch-specific code, here's the obligatory "don't just run any old .py file off the internet unless you or someone trustworthy knows it won't nuke your Switch"
 
  • Like
Reactions: AileenLumina
Hence why there will be a repository with trusted Python homebrew :)

Edit: We could also implement something similar to a sudo mode. If a Python app needs sudo privileges, the user will be notified and needs to confirm before the program is launched.
 
Last edited by AileenLumina,
Hence why there will be a repository with trusted Python homebrew :)

Edit: We could also implement something similar to a sudo mode. If a Python app needs sudo privileges, the user will be notified and needs to confirm before the program is launched.
Konami code would do nicely ;)
 
  • Like
Reactions: AileenLumina
Can anybody explain how to use switch specific functions and if there is any documentation of all switch functions (especially for buttons)?
 
Can anybody explain how to use switch specific functions and if there is any documentation of all switch functions (especially for buttons)?
Apart from what I sent: You could check the libnx documentation, but I would advise you to wait until I finished the high-level nx package. :)
 
  • Like
Reactions: Rauliki and DarkOrb
IMHO it should be handled like godmode9, were there are different levels of write permissions, which can be unlocked only by introducing a random, screen displayed combination of keys...
 
Yeah, something like that would work as well. ^^

On another note, save editing will be a feature in the next release, which may be out today already! :)
 
  • Like
Reactions: lordelan

Site & Scene News

Popular threads in this forum