amazon-orders Skill
Interact with your Amazon.com order history using the unofficial amazon-orders Python package and CLI.
Note: amazon-orders works by scraping/parsing Amazon's consumer website, so it can break if Amazon changes their pages. Only the English Amazon .com site is officially supported.
Setup
Install / upgrade
python3 -m pip install --upgrade amazon-orders
(Install details and version pinning guidance are in the project README.)
Authentication options
INLINECODE2 can get credentials from (highest precedence first): environment variables, parameters passed to AmazonSession, or a local config.
Environment variables:
export AMAZON_USERNAME="you@example.com"
export AMAZON_PASSWORD="your-password"
# Optional: for accounts with OTP/TOTP enabled
export AMAZON_OTP_SECRET_KEY="BASE32_TOTP_SECRET"
(OTP secret key usage is documented by the project.)
Usage
You can use amazon-orders either as a Python library or from the command line.
Python: basic usage
CODEBLOCK2
Full details (slower, more fields)
Some order fields only populate when you request full details; enable it when you need richer order data:
- - Python: INLINECODE5
- CLI:
--full-details on INLINECODE7
CLI: common commands
CODEBLOCK3
Tips
- - If your account has MFA enabled, prefer setting
AMAZON_OTP_SECRET_KEY for automated runs. - When automating, keep credentials out of shell history: use environment variables and a secret manager (1Password, Vault, GitHub Actions secrets, etc.).
Examples
Export yearly history to JSON
CODEBLOCK4
Quick totals check (requires jq)
CODEBLOCK5
Notes
- - This is an unofficial scraper-based tool (no official Amazon API).
- Official docs are hosted on Read the Docs for advanced usage and APIs (Orders, Transactions, etc.).
amazon-orders 技能
使用非官方的 amazon-orders Python 包和 CLI 与您的 Amazon.com 订单历史进行交互。
注意:amazon-orders 通过抓取/解析亚马逊消费者网站来工作,因此如果亚马逊更改其页面,它可能会失效。仅官方支持英文亚马逊 .com 网站。
设置
安装/升级
bash
python3 -m pip install --upgrade amazon-orders
(安装详情和版本锁定指南请参阅项目 README。)
身份验证选项
amazon-orders 可以从以下位置获取凭据(优先级从高到低):环境变量、传递给 AmazonSession 的参数或本地配置。
环境变量:
bash
export AMAZON_USERNAME=you@example.com
export AMAZON_PASSWORD=your-password
可选:对于启用了 OTP/TOTP 的账户
export AMAZON
OTPSECRET
KEY=BASE32TOTP_SECRET
(OTP 密钥的使用方法由项目文档说明。)
使用方法
您可以将 amazon-orders 作为 Python 库 或从 命令行 使用。
Python:基本用法
python
from amazonorders.session import AmazonSession
from amazonorders.orders import AmazonOrders
amazonsession = AmazonSession(EMAIL>, )
amazon_session.login()
amazonorders = AmazonOrders(amazonsession)
获取特定年份的订单
orders = amazon
orders.getorder_history(year=2023)
或使用时间过滤器获取近期订单
orders = amazon
orders.getorder
history(timefilter=last30) # 最近30天
orders = amazon
orders.getorder
history(timefilter=months-3) # 过去3个月
for order in orders:
print(f{order.ordernumber} - {order.grandtotal})
完整详情(较慢,更多字段)
某些订单字段仅在请求完整详情时才会填充;当您需要更丰富的订单数据时启用它:
- - Python:full_details=True
- CLI:在 history 命令中使用 --full-details
CLI:常用命令
bash
身份验证(交互式/如果已设置则使用环境变量)
amazon-orders login
订单历史
amazon-orders history --year 2023
amazon-orders history --last-30-days
amazon-orders history --last-3-months
提示
- - 如果您的账户启用了 MFA,建议在自动化运行时设置 AMAZONOTPSECRET_KEY。
- 自动化时,避免将凭据保存在 shell 历史中:使用环境变量和密钥管理器(1Password、Vault、GitHub Actions secrets 等)。
示例
将年度历史导出为 JSON
bash
amazon-orders history --year 2023 --full-details > orders_2023.json
快速总额检查(需要 jq)
bash
amazon-orders history --last-30-days --full-details | jq -r .[] | [.order
number, .grandtotal] | @tsv
说明
- - 这是一个非官方的基于抓取的工具(没有官方的亚马逊 API)。
- 官方文档托管在 Read the Docs 上,提供高级用法和 API(订单、交易等)。