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,

AileenLumina

Python main, software engineer and API designer
OP
Member
Joined
Sep 27, 2015
Messages
631
Trophies
0
Age
26
XP
614
Country
Germany
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! ^-^
 

TotalInsanity4

GBAtemp Supreme Overlord
Member
Joined
Dec 1, 2014
Messages
10,800
Trophies
0
Location
Under a rock
XP
9,814
Country
United States
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?
 

AileenLumina

Python main, software engineer and API designer
OP
Member
Joined
Sep 27, 2015
Messages
631
Trophies
0
Age
26
XP
614
Country
Germany
@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,

AileenLumina

Python main, software engineer and API designer
OP
Member
Joined
Sep 27, 2015
Messages
631
Trophies
0
Age
26
XP
614
Country
Germany
>>> 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/
 

TotalInsanity4

GBAtemp Supreme Overlord
Member
Joined
Dec 1, 2014
Messages
10,800
Trophies
0
Location
Under a rock
XP
9,814
Country
United States
>>> 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

AileenLumina

Python main, software engineer and API designer
OP
Member
Joined
Sep 27, 2015
Messages
631
Trophies
0
Age
26
XP
614
Country
Germany
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,

TotalInsanity4

GBAtemp Supreme Overlord
Member
Joined
Dec 1, 2014
Messages
10,800
Trophies
0
Location
Under a rock
XP
9,814
Country
United States
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

DarkOrb

Well-Known Member
Member
Joined
Oct 11, 2013
Messages
290
Trophies
0
Age
31
XP
874
Country
Germany
Can anybody explain how to use switch specific functions and if there is any documentation of all switch functions (especially for buttons)?
 

AileenLumina

Python main, software engineer and API designer
OP
Member
Joined
Sep 27, 2015
Messages
631
Trophies
0
Age
26
XP
614
Country
Germany
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

AileenLumina

Python main, software engineer and API designer
OP
Member
Joined
Sep 27, 2015
Messages
631
Trophies
0
Age
26
XP
614
Country
Germany
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

General chit-chat
Help Users
  • No one is chatting at the moment.
    meowie13 @ meowie13: hellooo everyone