Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what are the Best coding practice for creating python package

I am creating pypi python package and for that i tired many solution avilable in different websites.

  1. First of all I followed this Approach1, in this approach author has created class and functions but when tried this one my package gave me an error that no module and class name is not define
  2. I tired many other Approaches like this one Approach2 in this approach author created only functions without class and __init__.py
  3. and then tried this one also which is very common Approach3

and here is important files structure provided by pypi officials

├── LICENSE
├── README.md
├── example_pkg
│   └── __init__.py
├── setup.py
└── tests

I am ready with my package but after spending whole night finding which one is Best coding practice? and now got confused

so my questions are as follows

  1. what is the use of file __init__.py?
  2. best practice for giving directory, class and functions names so that it will help during importing.because according to these answers some people said import directory name, some said filename followed by class etc..
  3. Can anyone provide me proper steps so that i can follow in upcoming packages also
like image 527
Mayur Satav Avatar asked Mar 07 '26 04:03

Mayur Satav


1 Answers

I'd recommend following the Python Packaging Authorities guides and tutorials at https://packaging.python.org.

In addition, the PyPA publishes an example project skeleton that you can use as a starting point: https://github.com/pypa/sampleproject/

like image 196
Dustin Ingram Avatar answered Mar 09 '26 17:03

Dustin Ingram



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!