Skip to main content

python-magento

This is a simple Python interface to Magento’s XML-RPC API. The API discovers and makes all of Magento’s API methods available to you.

Usage

from magento import MagentoAPI

magento = MagentoAPI("magentohost.com", 80, "test_api_user", "test_api_key")

magento.help() # Prints out all resources discovered and available.
# cart: create, info, license, order, totals
# cart_coupon: add, remove
# ... (a bunch of other resources)
# sales_order: addComment, cancel, hold, info, list, unhold

magento.sales_order.help() # 'sales_order' is a resource.
# sales_order: Order API
#   - addComment: Add comment to order
#   - cancel: Cancel order
#   - hold: Hold order
#   - info: Retrieve order information
#   - list: Retrieve list of orders by filters
#   - unhold: Unhold order

# Let's list sales and add their subtotals!
orders = magento.sales_order.list()
subtotals = [order["subtotal"] for order in orders]
revenue = sum(subtotals)

# Additionally, you can get API metadata from these calls:
json_description_of_resources = magento.resources()
json_description_of_possible_global_exceptions = magento.global_faults()
json_description_of_possible_resource_exceptions = magento.resource_faults("sales_order")

The API discovers and makes all of Magento’s API methods available to you. The best way to learn how to use the API is to play around with it in a Python shell and refer back to the Magento API documentation for docs on the usage of specific methods.

Quick IPython Shell

The Magento API is massive and takes effort to grok. If you need to use it in some production capacity, you’ll want to jump into a shell frequently and muck around with inputs and stare at outputs.

magento-ipython-shell will drop you into an IPython shell that has a variable bound to a MagentoAPI object that is ready for use.

The shell requires IPython, which is the bee’s knees. Install it and get it working first. Alternately, spin up a Python shell and instantiate the objects you need. This is just a slightly nicer way to get started mucking around.

Here’s how to launch it:

> magento-ipython-shell localhost.com 8888 api_user api_key

-- magento-ipython-shell -----------------
Connecting to 'http://localhost.com:8888/magento/api/xmlrpc'
Using API user/key api_user/api_key
Connected! The 'magento' variable is bound to a usable MagentoAPI instance.
-- magento-ipython-shell -----------------

Python 2.7.2 (default, Jun 16 2012, 12:38:40)
Type "copyright", "credits" or "license" for more information.

IPython 0.13.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]:

Now you can mess around with the magento instance.

In [1] magento
Out[1]: <magento.MagentoAPI at 0x107d3c310>

In [2]: magento.help() # Lists all the resources available and their methods.
Resources:

cart: create, info, license, order, totals
cart_coupon: add, remove
... (many more)

In [3]: magento.cart.help() # Describes the methods available under a resource.
cart: Shopping Cart
  - create: Create shopping cart
  - info: Retrieve information about shopping cart
  - license: Get terms and conditions
  - order: Create an order from shopping cart
  - totals: Get total prices for shopping cart

In [4]: len(magento.sales_order.list()) # Play around with output.
Out[4]: 2

Installation

python-magento is on PyPi:

  • pip install python-magento

  • easy_install python-magento

… or grab this code and run setup.py install

Metadata

Release files for python-magento 1.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 python-magento 1.0.3
File Size Uploaded
python-magento-1.0.3.tar.gz 7.0 kB Details

Release files / python-magento-1.0.3.tar.gz

Download URL python-magento-1.0.3.tar.gz
Size 7.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e61e1bada8d3688e8da5e13f72751ac5ea015505e9fe94bf3c29ec4e067591d6
BLAKE2b-256 checksum
How to use checksums
2d6af29576953149551e2cd926a30d12aa2ebb21239a82e90e8db03ec37015d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.0.3 This release

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.3.3

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.8

1 release file

0.2.7

1 release file

0.2.6

1 release file

0.2.5

1 release file

0.2.4

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.0

1 release file

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