This release is a pre-release and may not be stable for production use.
Periplus Proxy
Introduction
Periplus Proxy is a Python package designed to make it easy to implement the webhook interface that Periplus expects for loading data. It does so by using a dependency injection pattern where a handler function for fetching data is implemented by the user and passed to a templated controller class. This allows the user to only worry about implementing a function that takes a list of ids and returns the associated records. The package takes care of running the server with the correct webhook interface. Using this package is not required to use Periplus. Any webhook implementation that adheres to the specification will work.
Installation
You can install the package using pip:
pip install periplus-proxy
Usage
1. Setting Up Your Webhook
Here's a simple example that shows how to use the package to set up your webhook:
from periplus_proxy import ProxyController, Query, QueryResult, Record
# 1. Implement a function that adheres to the interface shown here.
async def fetch_ids(request: Query) -> QueryResult:
ids = request.ids
data = # Implement logic to fetch data with the ids. (data should be List[Record])
return QueryResult(results=data)
# 2. Initialize a ProxyController instance with the endpoint and handler function.
controller = ProxyController(endpoint='/api/fetch-data', fetch_ids=fetch_ids)
# 3. Run the server.
controller.run()
Here's a slightly more complex example for fetching data from Pinecone:
from periplus_proxy import ProxyController, Query, QueryResult, Record
from pinecone import Pinecone
pc = Pinecone(api_key='<PINECONE-API-KEY>')
index_name = '<PINECONE-INDEX-NAME>'
index = pc.Index(index_name)
def split_list(lst, chunk_size=100):
return [lst[i:i + chunk_size] for i in range(0, len(lst), chunk_size)]
async def fetch_ids(request: Query) -> QueryResult:
ids = request.ids
results = []
id_lists = split_list(ids)
for ids in id_lists:
response = index.fetch(ids=ids)
vectors = response['vectors']
for id, data in vectors.items():
results.append(Record(embedding=data['values'], document="", id=id, metadata=data['metadata']))
return QueryResult(results=results)
if __name__ == "__main__":
endpoint = "/api/v1/load_data"
controller = ProxyController(endpoint=endpoint, fetch_ids=fetch_ids)
controller.run(host='localhost', port=3000)
2. Running the Webhook
To start the server and make the webhook available, run your program:
python your_program.py
By default, the server will start on 0.0.0.0 at port 8000. You can customize the host and port by passing host and port arguments to the run() method as shown above.
3. Making a Request
You can send a POST request to your webhook with a JSON payload containing the IDs of the vectors you want to fetch:
{
"ids": ["id1", "id2", "id3"]
}
4. Example Response
The response will be a JSON object containing the fetched data:
{
"results": [
{
"embedding": [0.1, 0.2, 0.3],
"document": "document",
"id": "id1",
"metadata": "{}"
},
{
"embedding": [0.4, 0.5, 0.6],
"document": "document",
"id": "id2",
"metadata": "{}"
},
{
"embedding": [0.7, 0.8, 0.9],
"document": "document",
"id": "id3",
"metadata": "{}"
}
]
}
Webhook Specification
Endpoint
- URL:
/api/v1/load_data(This is flexible so long as the endpoint is correctly specified when initializing the Periplus instance) - Method: POST
- Content-Type:
application/json
Request Payload
The webhook expects a JSON payload with the following structure:
{
"ids": ["id1", "id2", "id3"]
}
- ids: An array of strings, where each string represents the ID of a vector stored in the database.
Response Payload
The response will be a JSON object containing the fetched data associated with the provided IDs:
{
"results": [
{
"embedding": [0.1, 0.2, 0.3],
"document": "document",
"id": "id1",
"metadata": "{}"
},
{
"embedding": [0.4, 0.5, 0.6],
"document": "document",
"id": "id2",
"metadata": "{}"
}
]
}
- results: An array of objects where each object represents the data associated with an ID.
- embedding: A list of floats representing the vector's embedding.
- document: A string that could represent additional information or a document associated with the vector.
- id: The ID of the vector.
- metadata: A string containing metadata associated with the vector.
Error Responses
- 422 Unprocessable Entity: If the incoming payload does not match the expected structure, the webhook will return a
422status code with details about the validation errors. - 500 Internal Server Error: If there is an issue with the handler function or the fetched data, the webhook will return a
500status code with an appropriate error message.
Requirements
- Python 3.8+
- FastAPI
- Pydantic
- Uvicorn
- Pinecone Python Client
Contributing
We welcome contributions to the Periplus Proxy! To contribute:
- Fork the repository.
- Create a new branch: git checkout -b feature/your-feature-name.
- Make your changes.
- Commit your changes: git commit -m 'Add some feature'.
- Push to the branch: git push origin feature/your-feature-name.
- Open a pull request.
License
This project is licensed under the MIT License.
Metadata
Release files for periplus-proxy 0.1.0a1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| periplus_proxy-0.1.0a1.tar.gz | 5.0 kB | Without provenance | Details for periplus_proxy-0.1.0a1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| periplus_proxy-0.1.0a1-py3-none-any.whl | Python 3 | none | any | Details for periplus_proxy-0.1.0a1-py3-none-any.whl |
Total release size: 10.5 kB
Release files / periplus_proxy-0.1.0a1.tar.gz
| Download URL | periplus_proxy-0.1.0a1.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e20ee96cc5c6ecd2b42657b6d825ebb37122a5721f9b803e2f23dc3fbb08944a
|
|
BLAKE2b-256 checksum How to use checksums |
9b5edb634b603a4e7248ca5d69e2d50f96adb5709ade4f120f8d76ad2585e9a7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.10.13
|
Release files / periplus_proxy-0.1.0a1-py3-none-any.whl
| Download URL | periplus_proxy-0.1.0a1-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d9a014aabbe62e984f6009d94c4472b2ac2253292934e960d6d86cf4eebfedbc
|
|
BLAKE2b-256 checksum How to use checksums |
67142af75bdb2ca0cbde57ca301c86bd34c6b5c2f2c26a02b7dd4219dcc862d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.10.13
|
Security for periplus-proxy 0.1.0a1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.