Package: woocommerceaio
woocommerceaioAn async Python wrapper for the WooCommerce REST API based onhttpx.This is anunofficialfork of theWooCommerce-provided Python client, originally created by Claudio Sanches.The main difference betweenwoocommerceaioand the official client resides in the use of the async HTTP libraryhttpxinstead ofrequests.Other differences include:Support for retries.Type hints.And more to come (as I use the library I need to add more features)InstallationpipinstallwoocommerceaioGetting startedGenerate API credentials (Consumer Key & Consumer Secret) following this instructions athttp://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/.SetupfromwoocommerceaioimportAPIwcapi=API(url="http://example.com",consumer_key="ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",consumer_secret="cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",version="wc/v3")OptionsOptionTypeRequiredDescriptionurlstringyesYour Store URL, example:http://woo.dev/consumer_keystringyesYour API secret keyconsumer_secretstringyesYour API consumer secretversionstringnoAPI version, default iswc/v3timeoutintegernoConnection timeout, default is5verify_sslboolnoVerify SSL when connect, use this option asFalsewhen need to test with self-signed certificatesquery_string_authboolnoForce Basic Authentication as query string whenTrueand using under HTTPS, default isFalseuser_agentstringnoSet a custom User-Agent, default iswoocommerceaio/<version>oauth_timestampintegernoCustom timestamp for requests made with oAuth1.0awp_apiboolnoSet toFalsein order to use the legacy WooCommerce API (deprecated)MethodsYou can interact with the WooCommerce API using via the exposed methodsget(),post(),put(),delete(),options().All methodsthe following parameters.ParamsTypeDescriptionendpointstringWooCommerce API endpoint, example:customersororder/12datadictionaryData that will be converted to JSON**kwargsdictionaryAcceptsparams, also otherhttpxarguments (see next section)kwargs paramswoocommerceaioallows you to pass anyhttpxarguments askwargsparams. This is useful if you want to customize headers, timeouts, and other request parameters. For a list of available params, refer to thehttpx documentation.Additionally,woocommerceaioprovides the following customkwargsparams:ParamsTypeDescriptionmax_retriesboolMaximum number of retries on failed requests. Default is3retry_backofffloatBackoff time to apply between attempts after the second try (most errors are resolved immediately by a second try without a delay). Default is0.5seconds. This value will be multiplied by a factor of two for each consequent retry. So the default delay sequence will be0.5,1,2,4,8etc. secondsResponseAll methods will return an httpxResponseobject. For more information on how to use this object, refer to thehttpx documentation.ExamplesRetrieving store products>>>r=awaitwcapi.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,...'//Jsontext>>>r.json(){u'products':[{u'sold_individually':False,...//DictionarydataMaking requests withparamsfromwoocommerceaioimportAPIasyncdefexample():wcapi=API(url="http://example.com",consumer_key="ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",consumer_secret="cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",version="wc/v3")# Force delete example.response=awaitwcapi.delete("products/100",params={"force":True})print(response.json())# Query example.response=awaitwcapi.get("products",params={"per_page":20})print(response.json())if__name__=="__main__":importasyncioloop=asyncio.get_event_loop()loop.run_until_complete(example())ChangelogSeeCHANGELOG.md.