Skip to main content

🦊 web2sdk

Automatically turn third party APIs into Python SDKs

License Issues

Web2sdk is a set of tools for reverse engineering APIs by intercepting network requests. It processes HAR files exported from Chrome devtools into an OpenAPI schema, then automatically generates a python SDK based on the schema. Each method in the python SDK corresponds to an endpoint, and includes strongly typed arguments, requests, and responses.

https://github.com/user-attachments/assets/5a7f477d-76ab-46f2-9884-62dfc9f2715b

Features

  • Generates an OpenAPI/Swagger yaml schema from any web-based flow
  • Automatically merges requests to the same endpoint
  • Generates pydantic classes based on OpenAPI request and response schemas
  • Supports basic and bearer auth schemes
  • Supports overriding default headers

Usage

1. Export HAR file

  • Open Chrome devtools and go to "Network".

  • Go through a flow on a website that triggers the requests you want to capture and reverse engineer. The more varied the requests the better, as a single request might not capture all the possible request and response schemas for a particular endpoint.

  • Click the button shown below to export the HAR file. Don't worry about filtering out requests, that happens later.

  • Also compatible with mitmweb exports.

    CleanShot 2024-08-27 at 21 11 53

2. Install web2sdk

$ pip install web2sdk

3. Generate an OpenAPI spec and SDK

$ web2sdk --requests-path <path/to/har/or/flow/file> --base-url <https://finic.ai/api/v1> --sdk-name FinicSDK --auth-type bearer
  • base-url filters out requests that don't start with the url provided. This should include everything up until the endpoints you want to reverse engineer.
  • For example, https://finic.ai/api/v1 will match only requests to the v1 endpiont, but https://finic.ai/api will match requests from v1, v2, and any other paths after /api.
  • Generated files will be saved to generated/<sdk_name>.yaml and generated/<sdk_name>.py in the current directory by default.

4. Run your python SDK.

from generated.FinicSDK import FinicSDK

finic = FinicSDK(hostname="finic.ai", token="your_token_here")
finic.get_connectors({})
finic.post_message({ message: "hi there" }, override_headers={ "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)" })
  • Each method in the generated SDK corresponds to an endpoint
  • You can pass in any headers you want. By default, only Authorization and User-Agent headers are included.
  • Some methods accept parameters and/or request bodies. Inspect the function to see what arguments it takes.

Other Options

-- auth <basic|bearer>

  • Optional, defaults to none. If set, the generated SDK class will expect a username and password for basic auth or a token for bearer auth.

--output

  • Optional, defaults to generated/ in the current directory. Specify a directory for the generated .yaml and .py files to be saved.

--interactive

  • Run in interactive mode. Not well supported.

🚧 Planned Improvements

  • Support for oauth and custom auth schemes. In the mean
  • Automatic auth token refresh
  • Support for templated API paths (e.g. https://api.claude.ai/api/organizations/{organization_id}/chat_conversations)
  • Use LLMs to generate more readable class names, example request payloads, and other tasks that require fuzzy reasoning
  • Include a linter/formatter to make generated SDK more readable

Acknowledgements

Web2sdk's includes a modified version of mitmproxy2swagger.

Metadata

Release files for web2sdk 0.0.3

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

Source distribution (sdist)

Source distribution for web2sdk 0.0.3
File Size Uploaded Provenance
web2sdk-0.0.3.tar.gz 19.2 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 41.4 kB

Release files / web2sdk-0.0.3.tar.gz

Download URL web2sdk-0.0.3.tar.gz
Size 19.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c5a7af6f2103bde14b7663c24df970d50548880b06402f6c6416b654928fa96d
BLAKE2b-256 checksum
How to use checksums
93671291f1afe431fdbce8f2cd3f88071fd65eea81680606105e3e377e2a9f9b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.10.14 Darwin/23.6.0

Release files / web2sdk-0.0.3-py3-none-any.whl

Download URL web2sdk-0.0.3-py3-none-any.whl
Size 22.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f3f6f8c1c971e085b451304e13733ebf37482813a4f047c573f60865b69b88ba
BLAKE2b-256 checksum
How to use checksums
c0938a4115d9213a6b3ab9ed059ac34c690cf7748039edc972f7c05406d17422
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.10.14 Darwin/23.6.0

Security for web2sdk 0.0.3

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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