From b0ac92668d54b3233752e05f47cca576c5e21bd2 Mon Sep 17 00:00:00 2001
From: ghaymah_dev
Date: Wed, 29 Oct 2025 13:29:52 +0000
Subject: [PATCH] Add client.py
---
client.py | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
create mode 100644 client.py
diff --git a/client.py b/client.py
new file mode 100644
index 0000000..66d04fc
--- /dev/null
+++ b/client.py
@@ -0,0 +1,36 @@
+# بسم الله الرحمن الرحيم
+
+from http.client import HTTPSConnection
+from base64 import b64encode
+from json import loads
+from json import dumps
+
+class RestClient:
+ domain = "api.dataforseo.com"
+
+ def __init__(self, username, password):
+ self.username = username
+ self.password = password
+
+ def request(self, path, method, data=None):
+ connection = HTTPSConnection(self.domain)
+ try:
+ base64_bytes = b64encode(
+ ("%s:%s" % (self.username, self.password)).encode("ascii")
+ ).decode("ascii")
+ headers = {'Authorization' : 'Basic %s' % base64_bytes, 'Content-Encoding' : 'gzip'}
+ connection.request(method, path, headers=headers, body=data)
+ response = connection.getresponse()
+ return loads(response.read().decode())
+ finally:
+ connection.close()
+
+ def get(self, path):
+ return self.request(path, 'GET')
+
+ def post(self, path, data):
+ if isinstance(data, str):
+ data_str = data
+ else:
+ data_str = dumps(data)
+ return self.request(path, 'POST', data_str)