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,
D

Deleted User

Guest
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.

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 | Discord | Source

Special thanks to DavidBuchanan314, @MarcusD, @Stary2001 and several other people from ReSwitched as well as the SwitchBrew team, the devkitPro team, and the Python Software Foundation.


"What would be the ideal coding language to make homebrew apps when the Switch gets hacked?"
:)

Excellent work!

Do you have any plans to bring over some of the more popular packages, such as numpy or matplotlib?
 
  • Like
Reactions: TotalInsanity4

AileenLumina

Python main, software engineer and API designer
OP
Member
Joined
Sep 27, 2015
Messages
631
Trophies
0
Age
26
XP
614
Country
Germany
Yes, both are planned, but many scientific packages (e.g. the ones you named) require a Fortran compiler. This is in the works, though, so fear not. :)

Also, after taking a short break (sorry 'bout that :P), I just finished implementing Savedata read/write, which means you can now start writing savedata editors for Switch games in Python. Here is some example code:

import nx
BOTW_TITLE_ID = 0x01007ef00011e000 # title IDs are just hexadecimal numbers
botw = nx.titles[BOTW_TITLE_ID]
with botw.savedata.open('0/save_game.sav') as savegame_file:
# do something with savegame_file, it's just a regular file object​

As you can see, I used the new nx package to get a botw Title object from nx.titles. Then I opened a file in botw's savedata, which provides me with a regular file object. It's that simple. (The open method takes the same arguments as pathlib.Path.open, in addition to the file_path as its first positional argument.)

If you want to experiment a bit, there's also a TCP REPL example script which you can use as a replacement to your main.py. It allows you to enter Python code via your PC and let your Switch run it.

Warning: Do not edit your savedata without backing it up, or you will risk losing it! As stated in the license of PyNX, nx and _nx, we cannot be held liable for any damage caused by the usage of the software. Be careful and create a backup before you edit a game's savedata.


10 hours later...

I just released v0.3.0-alpha (and I forgot to actually submit this post before, oops). It adds the aforementioned functions plus controller input:

import nx
while True:
if nx.p1.a_button.is_pressed:
print("a", end="")​

Enjoy! :)
 
Last edited by AileenLumina, , Reason: Updated TCP REPL script link

lordelan

Well-Known Member
Member
Joined
Jan 4, 2015
Messages
5,788
Trophies
1
Age
44
XP
6,518
Country
Germany
Yes, both are planned, but many scientific packages (e.g. the ones you named) require a Fortran compiler. This is in the works, though, so fear not. :)

Also, after taking a short break (sorry 'bout that :P), I just finished implementing Savedata read/write, which means you can now start writing savedata editors for Switch games in Python. Here is some example code:

import nx
BOTW_TITLE_ID = 0x01007ef00011e000 # title IDs are just hexadecimal numbers
botw = nx.titles[BOTW_TITLE_ID]
with botw.savedata.open('0/save_game.sav') as savegame_file:
# do something with savegame_file, it's just a regular file object​

As you can see, I used the new nx package to get a botw Title object from nx.titles. Then I opened a file in botw's savedata, which provides me with a regular file object. It's that simple. (The open method takes the same arguments as pathlib.Path.open, in addition to the file_path as its first positional argument.)

If you want to experiment a bit, there's also a TCP REPL example script which you can use as a replacement to your main.py. It allows you to enter Python code via your PC and let your Switch run it.

Warning: Do not edit your savedata without backing it up, or you will risk losing it! As stated in the license of PyNX, nx and _nx, we cannot be held liable for any damage caused by the usage of the software. Be careful and create a backup before you edit a game's savedata.


10 hours later...

I just released v0.3.0-alpha (and I forgot to actually submit this post before, oops). It adds the aforementioned functions plus controller input:

import nx
while True:
if nx.p1.a_button.is_pressed:
print("a", end="")​

Enjoy! :)
That's such a great update! Can't believe no one is commenting on this. Really appreciate your work! PyNX is one of the most fun things to follow on the Switch these days. Please keep it up! :)
 
  • 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
Thank you!

On that note, I'd like to announce that our first small community project will be a BotW savedata editor. This will be an opportunity for you to dive right into learning how to write Python homebrew for the Switch, so don't miss out! If you would like to join us, please check out our Discord community. No prior experience with Python required, as long as you're willing to learn, we'll be happy to get you started!

Edit: I forgot to mention that v0.3.1-alpha was released a few days ago. It fixes multiple bugs and adds virtual buttons:

abxy = (nx.p1.a_button, nx.p1.b_button, nx.p1.x_button, nx.p1.y_button)
abxy_button = nx.Button.from_buttons(*abxy)

abxy_button.is_pressed will be true if either A, B, X or Y is pressed. Enjoy! ^^
 
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
Thanks, I updated the link :)

I had to take a short break due to final exams, but I've got a few weeks of time to work on this again. ^^
 

AileenLumina

Python main, software engineer and API designer
OP
Member
Joined
Sep 27, 2015
Messages
631
Trophies
0
Age
26
XP
614
Country
Germany
Added full multitouch support and fixed issues with savedata writing. A new release will be out tomorrow, hopefully.

In the meantime,
please take a few minutes to participate in this quick survey. Your answers will help shape the future of nx-python.

Thank you for your time!
 
  • Like
Reactions: lordelan

lordelan

Well-Known Member
Member
Joined
Jan 4, 2015
Messages
5,788
Trophies
1
Age
44
XP
6,518
Country
Germany
Added full multitouch support and fixed issues with savedata writing. A new release will be out tomorrow, hopefully.

In the meantime,
please take a few minutes to participate in this quick survey. Your answers will help shape the future of nx-python.

Thank you for your time!
Great news. Did the survey. :)
 
  • 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
This isn't really something new, but I'll post it here regardless for increased visibility. You can type Python code on your PC to be executed on your Switch using the TCP REPL example as your main.py.

After you launch PyNX, connect to your Switch via a TCP client (Port 1337; you can find your Switch's IP address in the settings, under the "Internet" tab). On Linux, the command to do that is rlwrap cat | tee log.py | nc switch.ip 1337 (replace `switch.ip` with the IP address of your Switch). This also logs the input to log.py, which might be useful. You can exit the TCP REPL by typing exit().
 

cots

Banned!
Banned
Joined
Dec 29, 2014
Messages
1,533
Trophies
0
XP
1,952
Country
United States
Amazing work! I see a bright future for Switch homebrew. I'm glad developers are interested in the console as the homebrew scene for the PS3/WiiU/3DS hasn't really produced anything other then a few game ports, emulators and utilities. It would be nice to see some original content popping up like in the NDS/Wii scene.
 
  • Like
Reactions: AileenLumina

Dontwait00

Unknown
Member
Joined
Sep 3, 2017
Messages
272
Trophies
0
Age
31
XP
701
Country
Italy

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.

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.
this leads to python developers to break out they own limits, putting the best apps on Switch now!
 
  • Like
Reactions: AileenLumina

Cyan

GBATemp's lurking knight
Former Staff
Joined
Oct 27, 2002
Messages
23,749
Trophies
4
Age
45
Location
Engine room, learning
XP
15,649
Country
France
You can only have one main.py in the same folder?
you have to replace the file every time and only have one project at a time?

I guess a launcher could be written in python?
main.py to list sub-folders and other main.py projects?

I didn't try yet, but thank you for making and maintaining this :)
 
Last edited by Cyan,
  • 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
This should just be integrated to the actual homebrew launcher so fiddling around wouldn't be necessary.
You can only have one main.py in the same folder?
you have to replace the file every time and only have one project at a time?

I guess a launcher could be written in python?
main.py to list sub-folders and other main.py projects?
You can give this loader a try. Use it as your main.py; it should display a simple file browser that allows you to select a Python program to run. It is intended to be a temporary workaround until this upstream issue is resolved. (Please report back if it works. :P )

You can also use this TCP REPL script as your main.py for testing purposes.

Why is this on the homepage only now ? Great news!
I wasn't confident enough about the stability of nx-python until today. That's why I decided to contact T-hug today, not earlier. :)
 
Last edited by AileenLumina,

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    Veho @ Veho: Cool.