Skip to content

Commit 01c0181

Browse files
authored
x402 support (#89)
1 parent 0cb2823 commit 01c0181

28 files changed

+1415
-86
lines changed

.github/workflows/test.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,18 @@ jobs:
1616
strategy:
1717
fail-fast: false
1818
matrix:
19-
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
19+
include:
20+
- python-version: "3.9"
21+
tox: min
22+
- python-version: "3.9"
23+
- python-version: "3.10"
24+
tox: min-x402
25+
- python-version: "3.10"
26+
- python-version: "3.11"
27+
- python-version: "3.12"
28+
- python-version: "3.13"
29+
- python-version: "3.13"
30+
tox: x402
2031

2132
steps:
2233
- uses: actions/checkout@v4
@@ -30,7 +41,7 @@ jobs:
3041
python -m pip install tox
3142
- name: tox
3243
run: |
33-
tox -e py
44+
tox -e ${{ matrix.tox || 'py' }}
3445
- name: coverage
3546
if: ${{ success() }}
3647
uses: codecov/[email protected]

CHANGES.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Changes
22
=======
33

4+
0.8.0 (unreleased)
5+
------------------
6+
7+
* Added :ref:`x402 support <x402>`.
8+
49
0.7.1 (2025-06-05)
510
------------------
611

README.rst

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,22 @@ Installation
3535
3636
pip install zyte-api
3737
38-
.. note:: Python 3.9+ is required.
38+
Or, to use x402_:
39+
40+
.. _x402: https://www.x402.org/
41+
42+
.. code-block:: shell
43+
44+
pip install zyte-api[x402]
45+
46+
.. note:: Python 3.9+ is required; Python 3.10+ if using x402.
3947

4048
.. install-end
4149
4250
Basic usage
4351
===========
4452

45-
.. basic-start
53+
.. basic-key-start
4654
4755
Set your API key
4856
----------------
@@ -54,6 +62,9 @@ After you `sign up for a Zyte API account
5462
<https://app.zyte.com/o/zyte-api/api-access>`_.
5563

5664
.. key-get-end
65+
.. basic-key-end
66+
67+
.. basic-start
5768
5869
5970
Use the command-line client

docs/conf.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@
183183
# A list of files that should not be packed into the epub file.
184184
epub_exclude_files = ["search.html"]
185185

186+
# -- Smart quotes ------------------------------------------------------------
187+
# Disabled so that, in the CLI reference, ``--api-key` and similar options are
188+
# not turned into –api-key in descriptions.
189+
smartquotes = False
190+
186191

187192
# -- Extension configuration -------------------------------------------------
188193

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ python-zyte-api
1818
:maxdepth: 1
1919

2020
use/key
21+
use/x402
2122
use/cli
2223
use/api
2324

docs/intro/basic.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
Basic usage
55
===========
66

7+
.. include:: /../README.rst
8+
:start-after: basic-key-start
9+
:end-before: basic-key-end
10+
11+
To use x402_ instead, see :ref:`x402`.
12+
13+
.. _x402: https://www.x402.org/
14+
715
.. include:: /../README.rst
816
:start-after: basic-start
917
:end-before: basic-end

docs/use/api.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
Python client library
77
=====================
88

9-
Once you have :ref:`installed python-zyte-api <install>` and :ref:`configured
10-
your API key <api-key>`, you can use one of its APIs from Python code:
9+
Once you have :ref:`installed python-zyte-api <install>` and configured your
10+
:ref:`API key <api-key>` or :ref:`Ethereum private key <x402>`, you can use one
11+
of its APIs from Python code:
1112

1213
- The :ref:`sync API <sync>` can be used to build simple, proof-of-concept or
1314
debugging Python scripts.

docs/use/cli.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
Command-line client
55
===================
66

7-
Once you have :ref:`installed python-zyte-api <install>` and :ref:`configured
8-
your API key <api-key>`, you can use the ``zyte-api`` command-line client.
7+
Once you have :ref:`installed python-zyte-api <install>` and configured your
8+
:ref:`API key <api-key>` or :ref:`Ethereum private key <x402>`, you can use the
9+
``zyte-api`` command-line client.
910

1011
To use ``zyte-api``, pass an :ref:`input file <input-file>` as the first
1112
parameter and specify an :ref:`output file <output-file>` with ``--output``.

docs/use/x402.rst

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
.. _x402:
2+
3+
====
4+
x402
5+
====
6+
7+
It is possible to use :ref:`Zyte API <zyte-api>` without a Zyte API account by
8+
using the x402_ protocol to handle payments:
9+
10+
#. Read the `Zyte Terms of Service`_. By using Zyte API, you are accepting
11+
them.
12+
13+
.. _Zyte Terms of Service: https://www.zyte.com/terms-policies/terms-of-service/
14+
15+
#. During :ref:`installation <install>`, make sure to install the ``x402`` extra.
16+
17+
#. :ref:`Configure <eth-key>` the *private* key of your Ethereum_ account to
18+
authorize payments.
19+
20+
.. _Ethereum: https://ethereum.org/
21+
22+
23+
.. _eth-key:
24+
25+
Configuring your Ethereum private key
26+
=====================================
27+
28+
It is recommended to configure your Ethereum private key through an environment
29+
variable, so that it can be picked by both the :ref:`command-line client
30+
<command_line>` and the :ref:`Python client library <api>`:
31+
32+
- On Windows’ CMD:
33+
34+
.. code-block:: shell
35+
36+
> set ZYTE_API_ETH_KEY=YOUR_ETH_PRIVATE_KEY
37+
38+
- On macOS and Linux:
39+
40+
.. code-block:: shell
41+
42+
$ export ZYTE_API_ETH_KEY=YOUR_ETH_PRIVATE_KEY
43+
44+
Alternatively, you may pass your Ethereum private key to the clients directly:
45+
46+
- To pass your Ethereum private key directly to the command-line client, use
47+
the ``--eth-key`` switch:
48+
49+
.. code-block:: shell
50+
51+
zyte-api --eth-key YOUR_ETH_PRIVATE_KEY …
52+
53+
- To pass your Ethereum private key directly to the Python client classes,
54+
use the ``eth_key`` parameter when creating a client object:
55+
56+
.. code-block:: python
57+
58+
from zyte_api import ZyteAPI
59+
60+
client = ZyteAPI(eth_key="YOUR_ETH_PRIVATE_KEY")
61+
62+
.. code-block:: python
63+
64+
from zyte_api import AsyncZyteAPI
65+
66+
client = AsyncZyteAPI(eth_key="YOUR_ETH_PRIVATE_KEY")

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ ignore = [
154154
"zyte_api/errors.py" = ["UP007"]
155155
"zyte_api/stats.py" = ["UP007"]
156156

157+
[tool.ruff.lint.flake8-pytest-style]
158+
parametrize-values-type = "tuple"
159+
157160
[tool.ruff.lint.flake8-type-checking]
158161
runtime-evaluated-decorators = ["attr.s"]
159162

0 commit comments

Comments
 (0)