How do I make a Python Package?

I want to make a Python Package; And I don’t want a thousand complicated steps. I just want easy instructions.

Hey there, I got this link:

It’s quite useful.

Someone else made a module:

That ain’t na help mate. It’s just too complicated

It’s not that hard, you have to follow some steps because they are essencial for creating a package.

There’s a ton of tutorials in the internet and they all will give you the same answer here. Is just that since the tutorial is already done, it makes more sense to follow the tutorial than build a new one to give you here.

1 Like

Making a python package isn’t hard, you just have a folder with the python code and a file. The complicated part is publishing that code on some kind of package repository like PyPi. In that case there is no “simple” way to do it… although if you just follow the steps that WindLother gave you it’s not that difficult.

Here is a quick tutorial
Thing you will need:
a pypi account, a token set to all projects(through that account), a package name that have not been taken and not a potentially malicious package name(see more here)

In your repl, go to shell and type ‘poetry new {your package name here}’
You should get new folder/directory
Now move your code into the folder with the name you gave it through the shell command.
note: there is a test folder and a folder with the name of the project, put your code in the folder with the project name.

After you’re done, edit the project.toml
It is straight forward, just edit according to the tag, ask here if you don’t understand. You should also make the README.rst describing your project and its usage well.

When you want to publish it, I recommend you to use a code like this (you should add your pypi key as a secret (env variable) named ‘PYPI_API_KEY’)

cd ~/{repl name}/{project directory name}
rm -r dist
poetry update
poetry publish --build -vvv -u __token__ -p $PYPI_API_KEY

run it and done.

Any error and ask here.

note: all curly brackets in this post ‘{}’ is something you should replace it with something described inside, such as replace {repl name} with your repl name, replit will NOT replace those curly brackets for you

1 Like

This can be replaced by $REPL_SLUG actually, it’s an environment variable replit sets.

1 Like