Reusing Python code¶
When you write a lot of Python code in a project, or across projects, you will often want to make reusable parts of code.
DSS provides several mechanisms for reusing Python code:
Packaging your code as functions or modules, and making them available in a specific project
Importing code that has been made available from one project to another
Packaging your code as functions or modules, and making them available in all projects
Packaging your code as a reusable plugin, and making it available for coder and non-coder users alike
Importing libraries from other projects¶
If you have created libraries in a project A, you can import them in project B. The libraries of project A will be added to the source path of all code running in project B.
Go to the library editor of project B
Open the
external-libraries.json
fileEdit the
importLibrariesFromProjects
list and add the project key (which appears in the URL, i.e. not the project display name) to itSave the
external-libraries.json
file
You need to have “Read project content” permission on A and “write project content” on B.
Manual editing of code library folders¶
Although not recommended, if you have shell access to the DSS machine, you can modify the library folders directly:
Per-project library folder is in
DATA_DIR/config/projects/PROJECT_KEY/lib
Global library folder is in
DATA_DIR/lib/python
Packaging code as plugins¶
See Plugins