-
Notifications
You must be signed in to change notification settings - Fork 6
x402 support #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
x402 support #89
Changes from 21 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
0692f65
x402 support: initial draft
Gallaecio b0be889
x402: optimize out initial requests where possible
Gallaecio 0df1f92
Add a n_x402_req stat
Gallaecio 2f3c9c4
Raise non-402 response as RequestError
Gallaecio 53f9a4c
Handle import errors from x402
Gallaecio 33dcc3e
Add x402 envs to tox and CI
Gallaecio 8970a7f
Keep mypy happy
Gallaecio 115abc5
Complete branch coverage
Gallaecio 27a3b13
Use a custom retry policy for x402 initial requests
Gallaecio e20d1ed
Remove unneeded skip
Gallaecio 9b42f98
Test command call with an env key
Gallaecio 12ec3a4
Test command when an Ethereum private key is set as an env var
Gallaecio ad3a1bb
Keep mypy happy
Gallaecio cae7b64
Fix min-x402 in CI
Gallaecio 3720c9b
Clarify required Python version
Gallaecio 1f80f57
Let --eth-key take precedence over ZYTE_API_KEY
Gallaecio dec667f
Handle race conditions and unexpected server responses
Gallaecio a5b5e40
Improve error mapping
Gallaecio 433dbc8
Complete test coverage, fix backward compatibility, and add client.au…
Gallaecio 9d5115b
Expose AuthInfo
Gallaecio 5b00725
AuthInfo.key_type → type
Gallaecio e3931c7
Update tests/mockserver.py
wRAR 3557ff1
Update tests/mockserver.py
wRAR 852fb1c
Add release notes
Gallaecio 46a3bdd
Prepare release notes, set the right endpoint for x402
Gallaecio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ python-zyte-api | |
| :maxdepth: 1 | ||
|
|
||
| use/key | ||
| use/x402 | ||
| use/cli | ||
| use/api | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| .. _x402: | ||
|
|
||
| ==== | ||
| x402 | ||
| ==== | ||
|
|
||
| It is possible to use :ref:`Zyte API <zyte-api>` without a Zyte API account by | ||
| using the x402_ protocol to handle payments: | ||
|
|
||
| #. Read the `Zyte Terms of Service`_. By using Zyte API, you are accepting | ||
| them. | ||
|
|
||
| .. _Zyte Terms of Service: https://www.zyte.com/terms-policies/terms-of-service/ | ||
|
|
||
| #. During :ref:`installation <install>`, make sure to install the ``x402`` extra. | ||
|
|
||
| #. :ref:`Configure <eth-key>` the *private* key of your Ethereum_ account to | ||
| authorize payments. | ||
|
|
||
| .. _Ethereum: https://ethereum.org/ | ||
|
|
||
|
|
||
| .. _eth-key: | ||
|
|
||
| Configuring your Ethereum private key | ||
| ===================================== | ||
|
|
||
| It is recommended to configure your Ethereum private key through an environment | ||
| variable, so that it can be picked by both the :ref:`command-line client | ||
| <command_line>` and the :ref:`Python client library <api>`: | ||
|
|
||
| - On Windows’ CMD: | ||
|
|
||
| .. code-block:: shell | ||
|
|
||
| > set ZYTE_API_ETH_KEY=YOUR_ETH_PRIVATE_KEY | ||
|
|
||
| - On macOS and Linux: | ||
|
|
||
| .. code-block:: shell | ||
|
|
||
| $ export ZYTE_API_ETH_KEY=YOUR_ETH_PRIVATE_KEY | ||
|
|
||
| Alternatively, you may pass your Ethereum private key to the clients directly: | ||
|
|
||
| - To pass your Ethereum private key directly to the command-line client, use | ||
| the ``--eth-key`` switch: | ||
|
|
||
| .. code-block:: shell | ||
|
|
||
| zyte-api --eth-key YOUR_ETH_PRIVATE_KEY … | ||
|
|
||
| - To pass your Ethereum private key directly to the Python client classes, | ||
| use the ``eth_key`` parameter when creating a client object: | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| from zyte_api import ZyteAPI | ||
|
|
||
| client = ZyteAPI(eth_key="YOUR_ETH_PRIVATE_KEY") | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| from zyte_api import AsyncZyteAPI | ||
|
|
||
| client = AsyncZyteAPI(eth_key="YOUR_ETH_PRIVATE_KEY") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import pytest | ||
|
|
||
| from zyte_api.apikey import NoApiKey, get_apikey | ||
|
|
||
|
|
||
| def test_get_apikey(monkeypatch): | ||
| assert get_apikey("a") == "a" | ||
| with pytest.raises(NoApiKey): | ||
| get_apikey() | ||
| with pytest.raises(NoApiKey): | ||
| get_apikey(None) | ||
| monkeypatch.setenv("ZYTE_API_KEY", "b") | ||
| assert get_apikey("a") == "a" | ||
| assert get_apikey() == "b" | ||
| assert get_apikey(None) == "b" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.