import threading import time import uuid import requests class RateLimitedUploader: def __init__( self, file_path: str, url: str, num_threads: int, ) -> None: self.file_path = file_path self.url = url self.stop = False self.request_count = 0 self.start_time = None self.num_threads = num_threads def upload_file(self): with open(self.file_path, "rb") as f: files = {"file": f} response = requests.post( self.url, files=files, json={"filename": f"/experiment/file-size/1mb/{str(uuid.uuid4())}"}, headers={ "Authorization": "Bearer paste-your-token-here", "x-org-slug": "sparktx-dev", }, ) # print(response.status_code) # print HTTP status code for debugging if response.status_code != 200: print("Error:", response.content) def run(self) -> None: def rate_limited_upload() -> None: self.start_time = time.time() while not self.stop: self.upload_file() for _ in range(self.num_threads): thread = threading.Thread(target=rate_limited_upload) thread.start() # example usage uploader = RateLimitedUploader( "/home/artud/Desktop/1mb.txt", "https://api.sparktx-dev.tetrascience.com/v1/datalake/upload", 10, ) uploader.run()