Skip to main content

acctf

acctfは、銀行や証券会社をスクレイピングして入出金履歴、株や投信の保有数や取得価額、現在価格を取得するライブラリです。

下記の銀行等に対応しています。

銀行

  • 住信SBIネット銀行
    • 預金(ハイブリッド含む)(円のみ)
    • 入出金履歴
      • 代表口座
      • ハイブリッド預金口座
      • 目的別口座

その他

  • WealthNavi(円表示のみ)
    • 各資産クラス

利用方法

インストール

pip install acctf
playwright install chromium

uvを利用する場合:

uv add acctf
uv run playwright install chromium

注: v0.6.0 以降、ブラウザ自動化に Playwright を採用しています。 arm64 Linux (Raspberry Pi 5 など) では Chromium のみサポートされ、Firefox は動作しません。

サンプル

銀行

預金

from acctf.bank.sbi import SBI
from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch(headless=True)
    page = browser.new_page()

    sbi = SBI(page=page).login("<ユーザID>", "<パスワード>")
    b = sbi.get_balance("7654321")
    print(f"口座番号, 店舗, 残高, 口座タイプ")
    print(f"{b[0].account_number}, {b[0].branch_name}, {b[0].value}, {b[0].deposit_type}")

    sbi.logout()
    browser.close()
口座番号, 店舗, 残高, 口座タイプ
7654321, 本店, 1234567.0, DepositType.ordinary

入出金履歴

住信SBIネット銀行はUIの変更に伴い、履歴のCSVをダウンロードしてデータを取得する方式です。 ブラウザコンテキストを accept_downloads=True で生成する必要があります。 また、ダウンロードしたCSVファイルはデータ取得後に削除されます。

from pathlib import Path

from acctf.bank.sbi import SBI, AccountName
from acctf.bank import CurrencyType
from playwright.sync_api import sync_playwright
from datetime import date

download_directory = str(Path.cwd()) + "/tmp"

with sync_playwright() as p:
    browser = p.chromium.launch(headless=True)
    # CSVダウンロードのため accept_downloads=True が必須
    context = browser.new_context(accept_downloads=True)
    page = context.new_page()

    sbi = SBI(page=page).login("<ユーザID>", "<パスワード>")
    hist = sbi.get_transaction_history(
        "7654321",
        date(2023, 12, 1),
        date(2023, 12, 31),
        download_directory=download_directory,
        currency=CurrencyType.jpy,
        account_name=AccountName.Representative,  # 代表口座
    )
    hist += sbi.get_transaction_history(
        "7654321",
        date(2023, 12, 1),
        date(2023, 12, 31),
        download_directory=download_directory,
        currency=CurrencyType.jpy,
        account_name=AccountName.Hybrid,  # ハイブリッド預金口座
    )

    print(f"日付, 取引内容, 金額")
    for h in hist:
        print(f"{h.date}, {h.content}, {h.value}")

    sbi.logout()
    browser.close()

その他

WealthNavi

from acctf.other.wealthnavi import WealthNavi
from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch(headless=True)
    page = browser.new_page()

    w = WealthNavi(page=page).login("<ユーザID>", "<パスワード>", "<TOTP>")
    # Time-based One Time Passwordを設定していない場合
    # w = WealthNavi(page=page).login("<ユーザID>", "<パスワード>")
    print("資産クラス, 現在価格, 損益")
    for h in w.get_valuation():
        print(f"{h.name}, {h.value}, {h.pl_value}")

    w.logout()
    browser.close()
資産クラス, 現在価格, 損益
米国株(VTI), 123456.0, 12345.0
日欧株(VEA), 123456.0, 12345.0
新興国株(VWO), 123456.0, 12345.0
債券(AGG), 123456.0, 12345.0
金(GLD), 123456.0, 12345.0
金(IAU), 123456.0, 12345.0
不動産(IYR), 123456.0, 12345.0
現金, 123456.0, 0.0

arm64 環境について

Raspberry Pi 5 などの arm64 Linux 環境では、Playwright が公式に提供しているブラウザバイナリは Chromium のみ です。Firefox および branded Chrome は arm64 Linux では動作しません。

公式 Docker イメージ mcr.microsoft.com/playwright/python は linux/amd64 / linux/arm64 の multi-arch ビルドが提供されているため、Kubernetes クラスタ (arm64) 上でも追加設定なしに利用できます。Docker での実行サンプルは examples/ を参照してください。

v0.5.x からの移行

v0.6.0 で Selenium から Playwright へ移行しました。コンストラクタが driver= (Selenium WebDriver) から page= (Playwright Page) に変わります。

# v0.5.x (Selenium)
from selenium import webdriver
driver = webdriver.Chrome()
sbi = SBI(driver=driver).login(...)

# v0.6.0 (Playwright)
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
    browser = p.chromium.launch()
    page = browser.new_page()
    sbi = SBI(page=page).login(...)

timeout の単位が秒 (30) からミリ秒 (30000) に変わっています。

開発

このリポジトリは uv で依存関係を管理しています。

セットアップ

uv sync
uv run playwright install chromium

ビルド

uv build

dist/ 配下にホイール (.whl) と sdist (.tar.gz) が生成されます。

PyPIへの公開

uv publish

Release files for acctf 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for acctf 0.6.0
File Size Uploaded
acctf-0.6.0.tar.gz 16.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for acctf 0.6.0
File Interpreter ABI Platform
acctf-0.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 35.4 kB

Release files / acctf-0.6.0.tar.gz

Download URL acctf-0.6.0.tar.gz
Size 16.6 kB
Tags Source
SHA-256 checksum
How to use checksums
60da07f0a69f14377ca42a8ee2fee407843e8f70d2e58ac52ffaa2543d93fd27
BLAKE2b-256 checksum
How to use checksums
a8c988a55dfc5a737e1916005e500523a527462f2189141e0dd4aa9f40934df4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 14, 2026.

Transparency log

Release files / acctf-0.6.0-py3-none-any.whl

Download URL acctf-0.6.0-py3-none-any.whl
Size 18.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8c664c170c8662674bf62db294634031e2e8b9c7cbf2b3ad93ebac1e0a913020
BLAKE2b-256 checksum
How to use checksums
04c2f8968e6c8300d18e16028d3aa1234299075f74e8ddc2f55735ded14a1576
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 14, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 release files

0.5.5

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

1 release file

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page