Registry / llm-agents / metaphor-python

metaphor-python

JSON →
library0.1.23pypypi✓ verified 85d ago

Metaphor-python is a Python client library for interacting with the Metaphor API, a search engine optimized for Large Language Models (LLMs). It enables neural search and content retrieval, providing clean HTML content from search results. The library is currently at version 0.1.23 and is under active development, indicated by its 'Alpha' status on PyPI. While no explicit release cadence is documented, updates are released as new features and improvements to the Metaphor API are made available.

pip install metaphor-python
INSTALL
IMPORT
SIG · METAPHOR-PYTHON
M
metaphor-python
llm-agentspythonv0.1.23
Install
2.1s avg
Import
596ms
Disk
19MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.23 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.628s · 21.2MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 2.1s · import 0.563s · 22MB
19MB installed
● package 19MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Metaphor
from metaphor_python import Metaphor

Initializes the Metaphor client using an API key from an environment variable and performs a basic search query, printing the title, URL, and a snippet of the content for the top results.

import os from metaphor_python import Metaphor # Ensure your Metaphor API key is set as an environment variable # e.g., export METAPHOR_API_KEY="your_metaphor_api_key_here" api_key = os.environ.get('METAPHOR_API_KEY') if not api_key: print("Error: METAPHOR_API_KEY environment variable not set.") else: try: metaphor = Metaphor(api_key=api_key) # Perform a search results = metaphor.search("latest developments in AI agents", num_results=3, use_autoprompt=True) if results.contents: print("Search Results:") for i, item in enumerate(results.contents): print(f"---\nResult {i+1}:\nTitle: {item.title}\nURL: {item.url}\nExtract: {item.extract[:200]}...") else: print("No search results found.") except Exception as e: print(f"An error occurred: {e}")
Debug
Known issues
gotchaThe Metaphor API key is crucial for authentication. Failing to provide a valid key will result in authentication errors when making API calls.
fix
Ensure the 'METAPHOR_API_KEY' environment variable is correctly set with your valid API key before initializing the Metaphor client. Alternatively, pass the key directly to the `Metaphor()` constructor: `metaphor = Metaphor(api_key='your_key')`.
affects: 0.1.x
gotchaThe library is in an 'Alpha' development status (0.1.x), meaning its API might evolve rapidly, and breaking changes could occur in minor or patch releases without strict adherence to semantic versioning until a 1.0 release.
fix
Monitor the official GitHub repository for changes and consult release notes (if available) when upgrading to new versions. Pin the version of `metaphor-python` in your `requirements.txt` to avoid unexpected breakage.
affects: 0.1.x
Errors
Common errors & fixes
metaphor_python.api.ApiException: (401) Reason: Unauthorized HTTP response body: b'{"detail":"Invalid API key"}'
The Metaphor API key provided is either missing, incorrect, or expired.
fix
Verify that your `METAPHOR_API_KEY` environment variable holds the correct and active API key obtained from the Metaphor website. Re-initialize the `Metaphor` client after updating the key.
AttributeError: 'Metaphor' object has no attribute 'some_non_existent_method'
Attempting to call a method or access an attribute that does not exist on the `Metaphor` client object or its response objects. This could be due to a typo or misunderstanding the available API methods.
fix
Consult the official Metaphor API documentation and the `metaphor-python` library's source or examples to ensure you are using the correct method names and arguments. The main methods are `search()`, `find_similar()`, and `get_contents()` (from the search results).
Upgrade
Version history
0.1.23latest on PyPI · released Nov 30, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
10
Amazon
1
OpenAI (training)
1
Resources
metaphor-python — pip install metaphor-python · libregistry