0 votes
1 view
in Python by (7.3k points)

I've been making Python scripts for simple tasks at work and never really bothered packaging them for others to use. Now I have been assigned to make a Python wrapper for a REST API. I have absolutely no idea on how to start and I need help.

What I have:

(Just want to be specific as possible) I have the virtualenv ready, it's also up in github, the .gitignore file for python is there as well, plus, the requests library for interacting with the REST API. That's it.

Here's the current directory tree

├── bin 

│   └── /the usual stuff/ 

├── include 

│   └── /the usual stuff/ 

├── lib 

│   └── python2.7 

│       └── /the usual stuff/ 

├── local 

│   └── /the usual stuff/ 

└── README.md 

27 directories, 280 files

I don't even know where to put the .py files if I ever make one.

What I wanted to do:

Make a python module install-able with "pip install ..."

If possible, I want a general step by step process on writing Python modules.

1 Answer

0 votes
by (107k points)

To write a Python module/package write the file name and the module name with the suffix .py.

An example that creates hello.py then writes the following function as its content:

def helloworld():


We can also import hello after you save the above code’s file in the .py format below is an example that shows how to import hello:-

import hello


If you want to group many .py files and want to put them in a folder. Then any folder with an __init__.py can be considered as a module by python and you can call them a package.

|-HelloModule |_ __init__.py |_ hellomodule.py

Welcome to Intellipaat Community. Get your technical queries answered by top developers !