Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A Python wrapper for the WooCommerce API.

License

NotificationsYou must be signed in to change notification settings

rooprob/wc-api-python

 
 

Repository files navigation

Having no feedback from the creator of wc-api-python, I have forked the project to add the session functionality of requests and the Retry functionality

A Python wrapper for the WooCommerce REST API. Easily interact with the WooCommerce REST API using this library.

https://github.com/woocommerce/wc-api-python/actions/workflows/ci.yml/badge.svg?branch=trunk

Installation

pip install -U git+https://github.com/<user>/<repo>@tag

Getting started

Generate API credentials (Consumer Key & Consumer Secret) following this instructionshttp://woocommerce.github.io/woocommerce-rest-api-docs/#rest-api-keys.

Check out the WooCommerce API endpoints and data that can be manipulated inhttp://woocommerce.github.io/woocommerce-rest-api-docs/.

Setup

fromwoocommerceimportAPIwcapi=API(url="http://example.com",consumer_key="ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",consumer_secret="cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",version="wc/v3")

Options

OptionTypeRequiredDescription
urlstringyesYour Store URL, example:http://woo.dev/
consumer_keystringyesYour API consumer key
consumer_secretstringyesYour API consumer secret
versionstringnoAPI version, default iswc/v3
timeoutintegernoConnection timeout, default is5
verify_sslboolnoVerify SSL when connect, use this option asFalse when need to test with self-signed certificates
query_string_authboolnoForce Basic Authentication as query string whenTrue and using under HTTPS, default isFalse
user_agentstringnoSet a custom User-Agent, default isWooCommerce-Python-REST-API/3.0.0
oauth_timestampintegernoCustom timestamp for requests made with oAuth1.0a
retriesintnoSet to3 in order to retry 3 times before exiting.
backoff_factorfloatnoSet to0.3. Change how long the processes will sleep between failed requests (exponential).
status_forcelistlistnoSet to[500, 502, 503, 504, 429] List of status on which we have to try again

Methods

ParamsTypeDescription
endpointstringWooCommerce API endpoint, example:customers ororder/12
datadictionaryData that will be converted to JSON
**kwargsdictionaryAcceptsparams, also other Requests arguments

GET

  • .get(endpoint, **kwargs)

POST

  • .post(endpoint, data, **kwargs)

PUT

  • .put(endpoint, data), **kwargs

DELETE

  • .delete(endpoint, **kwargs)

OPTIONS

  • .options(endpoint, **kwargs)

Response

All methods will returnResponse object.

Example of returned data:

>>> r = wcapi.get("products")>>> r.status_code200>>> r.headers['content-type']'application/json; charset=UTF-8'>>> r.encoding'UTF-8'>>> r.textu'{"products":[{"title":"Flying Ninja","id":70,...' // Json text>>>r.json(){u'products': [{u'sold_individually': False,... // Dictionary data

Request with params example

fromwoocommerceimportAPIwcapi=API(url="http://example.com",consumer_key="ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",consumer_secret="cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",version="wc/v3")# Force delete example.print(wcapi.delete("products/100",params={"force":True}).json())# Query example.print(wcapi.get("products",params={"per_page":20}).json())

Changelog

SeeCHANGELOG.md.

About

A Python wrapper for the WooCommerce API.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python100.0%

[8]ページ先頭

©2009-2025 Movatter.jp