Skip to main content

Python library to connect to Magento Webservices.

Usage

import magento

url = 'http://domain.com/'
apiuser = 'user'
apipass = 'password'

# Create an instance of API
client = magento.API(url, apiuser, apipass)

# A filter expression as dictionary.
order_filter = {'created_at':{'from':'2011-09-15 00:00:00'}}
products = client.product.list(order_filter)

# Get a list of product types
product_types = client.product_types.list()

# Get a specific product
sku = 'prod1'
product = client.product.info(sku)

# Add comment to an order
order_increment_id = '100000001 '
status = 'canceled'
client.order.addcomment(order_increment_id, status)

All available APIs

  • Cart (client.cart)

  • CartCoupon (client.cart_coupon)

  • CartCustomer (client.cart_customer)

  • CartPayment (client.cart_payment)

  • CartProduct (client.cart_product)

  • CartShipping (client.cart_shipping)

  • Category (client.category)

  • CategoryAttribute (client.category_attribute)

  • Country (client.country)

  • CreditMemo (client.credit_memo)

  • Customer (client.customer)

  • CustomerAddress (client.customer_address)

  • CustomerGroup (client.customer_group)

  • Inventory (client.inventory)

  • Invoice (client.invoice)

  • Magento (client.magento)

  • Order (client.order)

  • Product (client.product)

  • ProductAttribute (client.product_attribute)

  • ProductAttributeSet (client.product_attribute_set)

  • ProductConfigurable (client.product_configurable)

  • ProductImages (client.product_images)

  • ProductLinks (client.product_links)

  • ProductTierPrice (client.product_tier_price)

  • ProductTypes (client.product_types)

  • Region (client.region)

  • Shipment (client.shipment)

  • Store (client.store)

Old deprecated example

The API was originally written with the requirement to call APIs individually with all the credentials. This led to very verbose code and a lot of repitition. While the behavior has not been deprecated, it is recommended to write all new code with the pattern shown in the above example.

import magento

url = 'http://domain.com/'
apiuser = 'user'
apipass = 'password'

with magento.Order(url, apiuser, apipass) as order_api:
    order_increment_id = '100000001 '
    status = 'canceled'
    order_api.addcomment(order_increment_id, status)

with magento.Store(url, apiuser, apipass) as store_api:
    store_id = '1'
    store_view_info = store_api.info(store_id)
    store_views = store_api.list()

 with magento.Magento(url, apiuser, apipass) as magento_api:
    magento_info = magento_api.info()

Calling custom classes from your own API extensions

You can ddirectly invoke the underlying call method to make calls directly.

result = client.call('custom_model.list', [])

Alternatively, you can also build sub classes of API to have a more pythonic structure. The subclasses are automatically registered with API when classes are created.

To ensure that they are registered before you create the first API instance, always have all your imports on the top of your magento module.

class CustomModel(API):
    def list(self):
        return self.call('custom_model.list', [])

which would be automatically registered as custom_model by the API metaclass. So you can now use

import magento
from my_custom_module import CustomModel

url = 'http://domain.com/'
apiuser = 'user'
apipass = 'password'

# Create an instance of API
client = magento.API(url, apiuser, apipass)

client.custom_model.list()

License

BSD 3-Clause

See LICENSE for more details

Release files for magento 3.1

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

Source distribution (sdist)

Source distribution for magento 3.1
File Size Uploaded
magento-3.1.tar.gz 15.8 kB Details

Release files / magento-3.1.tar.gz

Download URL magento-3.1.tar.gz
Size 15.8 kB
Tags Source
SHA-256 checksum
How to use checksums
1b96306a3c0bd544995e89977864c1bda07507c6995b08776e22a0825449794d
BLAKE2b-256 checksum
How to use checksums
6304d4143b7a7dfb0a54b864de91634c4bf89e757f8cf1ce5d1b1f33dbf86cb2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/2.7.15

Release history Release notifications | RSS feed

This release

3.1 This release

1 release file

3.0

1 release file

2.2

1 release file

2.1

1 release file

2.0

1 release file

1.3

1 release file

1.2

1 release file

1.1

1 release file

1.0

1 release file

0.4

1 release file

0.3

1 release file

0.2

1 release file

0.1.4

1 release file

0.1.1

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