How to Manage Importing Own Libraries for Advanced Python Codes in Workflows: Google Drive, GitHub, or Pipedream File Stores?

This topic was automatically generated from Slack. You can find the original thread here.

Hi, I have workflows that include somewhat advanced python codes. I’d like to rework some of that code to adopt a more OOO approach, how should I manage importing my own libraries into the python code blocks inside my workflows? Should I store them somewhere (google drive or github for example?) download them and import them or should I work with pipedream file stores? Not sure my current plan support the file stores though…

You should visit Pricing - Pipedream for the latest pricing, but I’ll do my best to answer. To manage importing your own libraries into the Python code blocks inside your Pipedream workflows, you have a few options: 1. Using PyPI Packages: - Pipedream supports importing any package from PyPI. You can simply include the package in your step’s code, and Pipedream will automatically install the dependency for you. For example: import requests 2. Storing Libraries on External Services: - If you have custom libraries that are not available on PyPI, you can store them on external services like Google Drive or GitHub. You can then download these libraries within your Python code step and import them. Here’s an example of how you might do this: import requests # Download the library from GitHub url = "https://raw.githubusercontent.com/yourusername/yourrepo/main/yourlibrary.py" response = requests.get(url) with open("/tmp/yourlibrary.py", "w") as f: f.write(response.text) # Import the downloaded library import sys sys.path.append("/tmp") import yourlibrary 3. Using Pipedream Data Stores: - If your current plan supports it, you can use Pipedream Data Stores to store your libraries. You can then retrieve and import them in your Python code steps. Here’s an example of how you might do this: ```
def handler(pd: “pipedream”): # Retrieve the library code from the data store library_code = pd.inputs[“data_store”].get(“yourlibrary”) # Write the library code to a file with open(“/tmp/yourlibrary.py”, “w”) as f: f.write(library_code) # Import the library import sys sys.path.append(“/tmp”) import yourlibrary

Yeah, I also wish there was a more straightforward way to do this as well.

We plan on supporting this natively in the future — it’s in the backlog, just needs to be prioritized