In order to use this Tool step, we would recommend having a beginner level of understanding of Python programming, or use our Chat to walk you through implementing it at chat.relevanceai.com.
What is Python?
Python is a widely used programming language known for its clarity and simplicity. It’s popular among beginners and experts alike because it’s easy to read, quick to write, and versatile enough for tasks ranging from web development and automation to data analysis and machine learning. With a massive library ecosystem and strong community support, Python is a powerful tool for solving real-world problems efficiently.Python Package Ecosystem
One of Python’s greatest strengths is its extensive package ecosystem. You can install and use any package available on the Python Package Index (PyPI), which hosts over 693,000 projects with millions of releases. This means you have access to virtually any functionality you need across countless domains.Popular Packages by Use Case
Data Analysis & Manipulation
Data Analysis & Manipulation
pandas- Data manipulation and analysisnumpy- Numerical computing and arraysmatplotlib- Data visualization and plottingseaborn- Statistical data visualizationplotly- Interactive data visualization
Web Scraping & HTTP Requests
Web Scraping & HTTP Requests
requests- HTTP library for making web requestsbeautifulsoup4- Web scraping and HTML parsingscrapy- Web crawling frameworkselenium- Browser automation and testing
Machine Learning & AI
Machine Learning & AI
scikit-learn- Machine learning librarytensorflow- Deep learning frameworkpytorch- Deep learning and neural networkstransformers- Pre-trained language modelsopenai- OpenAI API client
Data Processing & File Handling
Data Processing & File Handling
openpyxl- Excel file manipulationpython-docx- Word document processingPyPDF2- PDF file manipulationpillow- Image processing librarycsv- Built-in CSV file handling
API Integration & Communication
API Integration & Communication
flask- Lightweight web frameworkfastapi- Modern web API frameworkrequests-oauthlib- OAuth authenticationtwilio- SMS and communication APIsstripe- Payment processing
Database & Storage
Database & Storage
sqlalchemy- SQL toolkit and ORMpsycopg2- PostgreSQL adapterpymongo- MongoDB driverredis- Redis database client
Adding the Python Tool step into your Tool
- Creating a new Tool, then clicking or searching for the Python Tool step
- Click ’+ New item’ under ‘PyPI Packages’ if you need to install any packages, and enter the package name you need.
- Enter your code in the ‘Code’ field, including any imports you need.
- Click ‘Run step’ to run the Tool step
In order to access the output of this codeblock, you will need to return a value in the
return statement.Accessing variables
You can access Tool input variables, other Tool step outputs, and API keys you’ve created in Relevance in your Python Tool step.Input variables
You can access Input variables by simply using the variable name directly, where ‘name’ is the variable for your input.Other Tool step outputs
You can access other Tool step outputs by using the variable name directly, where ‘llm’ is the variable for the Tool step you’re trying to access the output of.{"answer": "Hello!"}, then:
llmreturns{"answer": "Hello!"}llm["answer"]returns"Hello!"
API keys
You can access one of your saved API keys by using this syntax, where ‘api_key’ is the title of your API key.Advanced Settings
Several advanced settings (Session ID, Number of GPUs, Number of CPU Cores, Memory Size, and Session Timeout) are only available when the backend is set to ‘Modal Labs’.
Backend
You can choose between two backend services to run the code, ‘Modal Labs’ or ‘Daytona’.Runtime Commands
You can include a list of Linux terminal commands to be run before running your code.Session ID
Define a custom session that saves all local variables between Python executions.Enable ‘Long Output’ Mode
Allow the output to be longer than 127,000 characters, in exchange for 2-4 seconds of extra latency.Number of GPUs
Allows you to specify a number of GPUs for your code to use.Number of CPU Cores
Allows you to specify a number of CPU cores for your code to use.Memory Size
Allows you to specify an amount of RAM for your code to use.Session Timeout
Allows you to specify (in seconds) how long the code should run before timing out.Raise Error
Allows you to specify how errors are raised:- Error with Full Traceback - Shows the complete error traceback including file names, line numbers, and the full call stack. This is useful for debugging complex issues.
- Error - Shows only the error message without the detailed traceback. This provides a cleaner output for production use.
- Print Error to Stderr - Prints the error to stderr instead of raising it, allowing your code to continue execution even when errors occur.
Enable fallback
If the selected backend fails, when this is selected, your code will attempt to run via the other backend.Common errors
Code execution timed out
Code execution timed out
This error indicates that the code took longer than the seconds allowed in the ‘Session timeout’ Advanced Setting, or exceeded our hard limit of four hours.
No return statement
No return statement
This error indicates that there is no return statement in the code. You will not be able to access the output of this codeblock unless you pass data in a return statement. If the transformed section of the output is showing
null, it means that there is nothing being returned from your code.
