How to create python libraries and how to import it in palantir foundry

1.4k views Asked by At

In order to generalize the python functions, I wanted to add functions to python libraries so that I can use these function across the multiple repositories. Anyone please answer the below questions.

1) How to create our own python libraries 2) how to import those libraries across multiple repositories

2

There are 2 answers

0
fmsf On
  1. How to create python libraries in Palantir Foundry?

To create a new library, you can do so by creating a new repository. When prompted to initialise the repository, you should have an option that reads:

Python Library
Template for publishing a Python library package. Consuming new libraries has changed,
please read README in library repository.

The readme will contain instructions on how to publish a library. It is recommended you understand how conda publishing channels work for this.

A note, avoid using _ in the library name, since it can cause problems. - is safe to use though.


  1. How to import a library in code authoring?

Once your library is publishing, you can add it to your conda recipe of the repository you want to consume the library in. You can find this in: transforms-python/conda_recipe/meta.yaml

Afterwards just add it to the list of under

requirements:
  run:
    - python
    - pandas
    - your-library-name

0
nicornk On

In addition to fmsf's answer, in the second step you might have to add the following content to the build.gradle of your transforms-python directory:

transformsPython { 
    sharedChannels "libs" 
}