Skip to content

Commit ac9b189

Browse files
Make examples runnable without installing the package
Examples import captcha_sdk, but running `python examples/foo.py` puts examples/ on sys.path instead of the repo root, so the import failed unless the package was installed or PYTHONPATH was set. Append the repo root to sys.path in the eight examples that import captcha_sdk. The remaining four call the API through requests directly and need no change. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent a06d6ec commit ac9b189

8 files changed

Lines changed: 16 additions & 0 deletions

File tree

‎examples/balance.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import os
1010
import sys
1111

12+
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
13+
1214
from captcha_sdk import CaptchaClient
1315

1416
# in this example we store the API key inside environment variables that can be set like:

‎examples/geetest_v3.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
import requests
1414

15+
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
16+
1517
from captcha_sdk import CaptchaClient
1618
from captcha_sdk.tasks import GeeTestTaskProxyless, GeeTestTask
1719

‎examples/geetest_v4.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import os
1111
import sys
1212

13+
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
14+
1315
from captcha_sdk import CaptchaClient
1416
from captcha_sdk.tasks import GeeTestTaskProxyless, GeeTestTask
1517

‎examples/image_to_text.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import sys
1212
from base64 import b64encode
1313

14+
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
15+
1416
from captcha_sdk import CaptchaClient
1517
from captcha_sdk.tasks import ImageToTextTask
1618

‎examples/recaptcha_v2.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import os
1010
import sys
1111

12+
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
13+
1214
from captcha_sdk import CaptchaClient
1315
from captcha_sdk.tasks import RecaptchaV2TaskProxyless, RecaptchaV2Task
1416

‎examples/recaptcha_v2_enterprise.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import os
1111
import sys
1212

13+
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
14+
1315
from captcha_sdk import CaptchaClient
1416
from captcha_sdk.tasks import RecaptchaV2EnterpriseTaskProxyless, RecaptchaV2EnterpriseTask
1517

‎examples/recaptcha_v3.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import os
1111
import sys
1212

13+
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
14+
1315
from captcha_sdk import CaptchaClient
1416
from captcha_sdk.tasks import RecaptchaV3TaskProxyless
1517

‎examples/turnstile.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import os
1111
import sys
1212

13+
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
14+
1315
from captcha_sdk import CaptchaClient
1416
from captcha_sdk.tasks import TurnstileTaskProxyless, TurnstileTask
1517

0 commit comments

Comments
 (0)