testrail-api is a Python wrapper for the TestRail API, enabling programmatic interaction with TestRail instances for managing test cases, runs, results, and more. It is actively maintained with frequent minor releases, typically addressing new TestRail API features, bug fixes, and Python version compatibility. The current version is 1.13.6.
pip install testrail-apiVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the TestRail API client using environment variables for credentials and fetch a list of projects. Ensure you replace the placeholder values or set your environment variables correctly.
Upgrade Python to 3.9 or higher, or explicitly install `testrail-api<1.13.4`.
Always pass your TestRail API key value to the `password` parameter when initializing `TestRailAPI`.
Wrap API calls in `try...except` blocks to catch potential `TestRailError` exceptions or other HTTP client errors and implement custom retry logic if necessary beyond the library's defaults.
Consult the library documentation for available bulk or paginated methods when fetching large collections of resources.
Double-check your TestRail URL, username, and API key (or password) to ensure they are correct and the user has API access permissions: `client = TestRailAPI('https://your-domain.testrail.io/', 'your_username', 'your_api_key_or_password')`Install the package using pip: `pip install testrail-api`
Access methods through the appropriate resource object, such as `case = client.cases.get_case(case_id)`
Check the TestRail instance status and the specific API endpoint being called for server-side errors; you might need to inspect the raw response text: `try: response_data = client.cases.get_case(case_id) except requests.exceptions.JSONDecodeError as e: print(f'API returned non-JSON: {e.response.text}')`Verify that all required parameters are provided with correct values and refer to valid, existing entities in TestRail, for example: `client.results.add_result_for_case(run_id=1, case_id=101, status_id=1)`
No dependency data recorded yet.