Skip to content

Latest commit

 

History

History
101 lines (63 loc) · 2.12 KB

README.md

File metadata and controls

101 lines (63 loc) · 2.12 KB

requestrepo Python client

Python bindings to automate requestrepo.com

Installation

pip install requestrepo

Basic Usage

Instantiate the Requestrepo class:

from requestrepo import Requestrepo  # Requestrepo, RequestRepo and requestrepo are accepted imports

client = Requestrepo() # new token printed to console
client = Requestrepo("your-token-here")

or via environment variables:

REQUESTREPO_TOKEN=token python your_script.py

Examples

Example 1: Async request retrieval via on_request

from requestrepo import Requestrepo

def on_request(request_data):
   print("New Request Received:", request_data)

client = Requestrepo(token="your-token-here")

print(client.subdomain) # abcd1234
print(client.domain) # abcd1234.requestrepo.com

client.await_requests()

Example 2: Synchronous request retrieval

from requestrepo import Requestrepo

client = Requestrepo(token="your_api_token")

print(client.subdomain) # abcd1234
print(client.domain) # abcd1234.requestrepo.com

# Get the latest request (blocks until one is received)
new_request = client.get_request()
print("Latest Request:", new_request)

Example 3: Retrieve old requests

You can iterate over all requests that are stored on the server:

from requestrepo import Requestrepo

client = Requestrepo(token="your_api_token")

for request in client.get_old_requests():
    print("Request:", request)

client.delete_all_requests() # clear all requests on the server

Example 4: Update HTTP response

You can update the response of a request by calling update_http method:

from requestrepo import Requestrepo # pip install requestrepo

client = Requestrepo(token="your_api_token")

print(client.subdomain) # abcd1234
print(client.domain) # abcd1234.requestrepo.com

client.update_http(raw=b"hello world")

# Get the latest request (blocks until one is received)
new_request = client.get_request()
print("Latest Request:", new_request)

Contributing

Contributions are welcome! Please submit a pull request or open an issue if you have any ideas or suggestions.

License

MIT