Hi im planning on making a 3d python library but I need some tips and how to get started on making a library
I’d highly recommend looking into existing libraries and seeing how they’re structured.
Projects like
I linked to the python roots for each of those, since that’s a good place to start. At the end of the day it comes down to what you’re trying to build. You don’t need to immediately have your project looking like one of those from day one, but it’s good to have them as a reference as your codebase grows.
I’ve written tons of small one of libraries that are usually only a few files too. It’s good to start off simple and only add new modules when one file becomes overwhelming to manage or you have a clear delineation of responsibility (e.g. renderer.py and loader.py).
As those responsibilities gain more complexity, you can migrate them into directories with an __init__.py that exposes the internals.
library
__init__.py
renderer
__init__.py
shapes.py
pipelines.py
...
loader
__init__.py
csv_loader.py
obj_loader.py
...
...
Follow the general guidelines when creating a library as you would any code:
- Make sure the functions, constants, classes, i.e. objects are all related. Group like objects together (i.e., functions with functions, classes with classes, constants with constants, etc.)
- Fully document each object with doc strings as per PEP 257.
- Name objects with names that are self explanatory. Follow
Pythonnaming convention as per PEP 8. - Make sure the objects are fully tested and verified to work as expected for all potential case scenarios prior to distribution. Have a colleague test your library if possible as an objective user.
Just my two cents. Good luck!
Both of the above are good recommendations, I would also look at Overview of Python Packaging - Python Packaging User Guide when you are ready to start packaging up your library for publishing.
