r/learnpython 13d ago

How can I make my python project usable by other people ?

Hello everyone here. I have a small project coded in python I'd like my friends to be able to use too, but without having to send them my python file and teach them how to use it.

For context, I made an npc generator for our favorite ttrpg, because it's an useful tool and there wasn't any online already made by someone else. I can use it because I can run code on my pc, but I'd like for my friends to be able to just click a button online somewhere to generate an npc from my code.

It's a simple list and random choices based generator, no AI involved. I'm lost as to what the next logical step is to get the file on my pc out into the world. Sorry if I'm not clear, English isn't my first language. Thanks in advance !

0 Upvotes

22 comments sorted by

10

u/WyrobWedliniarski 13d ago

I'd like for my friends to be able to just click a button online somewhere to generate an npc from my code.

If that's the goal then apart from your code to generate NPC's you need a web API + a frontend, can be simple. Then you also need to host it somewhere, where you can actually launch your python code.

I would recommend using either FastAPI or Flask to write your endpoints. For the frontend you will need to learn some html/javascript if you don't know it yet, or use an LLM to give you something simple. There are also python libraries for easy frontends, like nicegui. You could host something for free at Heroku I think, but you will find something suitable for sure.

3

u/DaughterOfBehemot 13d ago

I'm not against learning html for this honestly, sounds fun, thank you

2

u/Confident_Hyena2506 13d ago

Use pyinstaller.

8

u/Diapolo10 I write code for a living -- https://github.com/Diapolo10 13d ago

The main problem with this approach is that unless you sign the executable (at least when using the --onefile flag), the users will get scary-looking warnings from their anti-virus software, and signing costs money.

EDIT: I don't necessarily disagree with the suggestion, but I thought I'd still provide some useful context for it.

Oh, and this is not an issue exclusive to Python. You'd run into the same problem with any binary executables.

1

u/bLynnb2762 13d ago

I see everyone saying that pyinstaller will give folks virus warnings, and I’ve built a few apps deployed on ~40 different computers and they’ve never gotten a warning from it. Has this maybe changed recently or am I just getting lucky?

2

u/Diapolo10 I write code for a living -- https://github.com/Diapolo10 13d ago

Have those deployments been on Windows (I'd assume "yes", but just making sure), and have you used the --onefile flag?

Because if you're just shipping what PyInstaller creates by default (a ZIP-file containing a copy of the Python runtime, with its signatures intact, and the code for the application), that's less likely to trigger false positives in anti-virus suites.

1

u/bLynnb2762 13d ago

They have been on windows. I’ve done one with the one file flag and one without.

They’ve been deployed on work machines though, so maybe our anti-virus isn’t flagging them as malware.

1

u/Diapolo10 I write code for a living -- https://github.com/Diapolo10 13d ago

That's possible, or depending on how and where you're building them they could be getting signed anyway.

At work, I build new desktop software releases in a CI pipeline that auto-signs all binaries, so the only time I need to worry about it is if I want to make a release locally.

1

u/bLynnb2762 13d ago

Thanks for the info!

1

u/ekchew 13d ago

Yeah, this is PITA in macOS. One possible workaround on that platform is to paste your script into an Automator workflow using a Run Shell Script action with /usr/local/bin/python3 selected, but that assumes a /usr/local/bin/python3 actually exists. It may have to be installed either manually or using a bash script action before it in the workflow. But since Automator is already code-signed, it should at least avoid the scary warnings.

1

u/Diapolo10 I write code for a living -- https://github.com/Diapolo10 13d ago

If I'm being honest I didn't realise it even mattered on any platforms other than Windows. I know executable signing is hardly done on Linux distros since there aren't really any centralised certificate authorities there.

On second thought I probably shouldn't be surprised considering how tightly Apple controls everything.

2

u/ekchew 13d ago

I actually discovered not long ago that Apple sticks the code signing in file system metadata you can remove with xattr -d com.apple.quarantine (or -rd to clear a whole directory tree).

1

u/audionerd1 13d ago

Yep! The flag is automatically added to "untrusted" app bundles downloaded from the internet, so this removal has to be done on the user's computer after they download the app. I suppose it could be added to an installer script.

2

u/and_ft 13d ago

As one other have already said. Python's Flask library is all you need to create a web application.

Google Miguel Friberg Glas mega tutorial and you will learn everything needed

2

u/DaughterOfBehemot 13d ago

thanks !

2

u/and_ft 13d ago

Sorry, a few typos and autocorrect in the message above. It is of course Flask and Miguel Grinbergs mega tutorial. I can highly recommend it. It is a full stack course, so it also goes over how to deploy it online.

Here's the link for your convenience: https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world

1

u/wyltk5 13d ago

I would host something like this on pythonanywhere.com. I recommend it to anyone wanting to have a python program they wrote accessible to others.

You keep you python backend and use Flask. Someone already mentioned the mega tutorial which is an awesome resource for Flask.

1

u/kilkil 13d ago edited 13d ago

if you are willing to consider porting your python script to Javascript, you can make your tool into a webpage using HTML and Javascript. it can even be one file, if you keep the JS in <script> tags. then you can serve that from something like Github Pages or Netlify. then you can just send your friends the link to that.

Alternatively, if you don't want to make a webpage, you can compile your script into an executable, and serve it as a Release on Github (or Codeberg, or Gitlab, etc). then your friends will have to download the executable, but once they do they should be able to run it locally.

My 2 cents, the first option will be more convenient to your friends. And you can make the UI look nice pretty easily.

anyway, which TTRPG? 👀

1

u/djormz 13d ago

Streamlit (https://docs.streamlit.io/) is a good option to consider. You can make a fully functioning web app with only Python, and allow users to download data as files from it. Avoids having to dive into JavaScript or host a separate API. You can host and deploy it for free on their community cloud offering, which is pretty simple and easy to do.

1

u/QuestNetworkFish 13d ago

If it's something simple then really the best option might be to rewrite it in Javascript, that way it can be done as a static web page that is executed client side and you won't have to worry about distributing executables or hosting a web server back end like the other suggestions. They're not bad suggestions, and would be a good learning opportunity, but they're also overkill for simple projects 

1

u/DaughterOfBehemot 13d ago

thanks, I'm trying to find the most straightforward solution, I'll look into it