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

Comunitea/wc-api-python

 
 

Repository files navigation

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

Installation

pip install woocommerce

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
oauth_timestampintegernoCustom timestamp for requests made with oAuth1.0a
wp_apiboolnoSet toFalse in order to use the legacy WooCommerce API (deprecated)

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

2.1.1 - 2019/07/22

  • Updated Request library to 2.22.0.
  • Updated examples.

2.1.0 - 2019/01/15

  • Uses WP REST API by default, need to forcewp_api asFalse in order to use the legacy WooCommerce API.
  • Updated default REST API version towc/v3.

2.0.0 - 2019/01/15

  • Updated "Requests" library to version 2.20.0.
  • Added support for custom timestamps in oAuth1.0a requests withoauth_timestamp.
  • Allow pass custom arguments to "Requests" library.

1.2.1 - 2016/12/14

  • Fixed WordPress 4.7 compatibility.

1.2.0 - 2016/06/22

  • Added optionquery_string_auth to allow Basic Auth as query strings.

1.1.1 - 2016/06/03

  • Fixed oAuth signature for WP REST API.

1.1.0 - 2016/05/09

  • Added support for WP REST API.
  • Added method to do HTTP OPTIONS requests.

1.0.5 - 2015/12/07

  • Fixed oAuth filters sorting.

1.0.4 - 2015/09/25

  • Implementedtimeout argument forAPI class.

1.0.3 - 2015/08/07

  • Forced utf-8 encoding onAPI.__request() to avoidUnicodeDecodeError

1.0.2 - 2015/08/05

  • Fixed handler for query strings

1.0.1 - 2015/07/13

  • Fixed support for Python 2.6

1.0.1 - 2015/07/12

  • Initial version

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