Skip to content

CralixRaev/pyMoysklad

Repository files navigation

pyMoysklad

Work-in-Progress api wrapper for Moysklad JSON API 1.02

Usage

Create JSON API client:

from pymoysklad.json.client import JSONApi

client = JSONApi(("admin@company", "examplePassword"))
# or by using token
# client = JSONApi("your_token_goes_here")

Access one of an API entities:

products = client.product.list_product()

List method will return CollectionAnswer object, from that you can access rows or get an request meta\context

print(products.rows)
print(products.meta)
print(products.context)

Get method will return object itself by his UUID

product = client.product.get_product(UUID("10cb9bc1-1544-4245-bb79-fece6074544f"))

Delete method will delete object by his UUID

client.product.delete_product(UUID("10cb9bc1-1544-4245-bb79-fece6074544f"))

Create method will create and return newly created object or multiple objects, if you provide a list of them

from pymoysklad.json.entity.product import Product

product = client.product.create_product(Product(name="test"))

Edit method will edit and return edited object

edited_product = client.product.edit_product(UUID("10cb9bc1-1544-4245-bb79-fece6074544f"), Product(name="edited name", description="i can edit any field, by just providing it in this product object"))

Mass delete method will mass delete objects using theirs metas

products_to_delete = client.product.list_product(search="DELETEME")
metas = [product.meta for product in products_to_delete.rows]
client.product.mass_delete_product(metas)

To sort a collection just provide order keyword argument in list method. Order argument can contain list of tuples (order=[("name", "desc"), ("code", "asc")]) to provide sorting direction or simply be a list of strings (order=["name", "code"] to use default ascending sorting:

sorted_products = client.product.list_product(order=["price", ("name", "desc")])

To filter a collection provide filter keyword argument in list method. Filter argument should be a tuple of strings with format described in documentation (filter=('name!=Товар', 'price>=100'))

filtered_products = client.product.list_product(filter=('name!=Товар', 'price>=100'))

To search in a collection provide search keyword argument in list method. Search argument should be a string.

searched_products = client.products.list_product(search="Капибара")

Expanding

To expand some field in request use expand keyword argument in list method. Expand argument should be a string, containing field name, multiple field names delimited with commas or nested fields delimited by dots. demand.agent,organization

products_with_images = client.product.list_product(expand="images")

Limit and offset

To limit and offset collection use limit and offset keyword arguments

I encountered an problem\there isn't some entity like ...

Just create an issue and I will try to resolve it ASAP. Yup, even add some entity that i didn't added before

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages