Git Product home page Git Product logo

pymoysklad's Introduction

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

pymoysklad's People

Contributors

cralixraev avatar dependabot[bot] avatar ssimuss avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

ssimuss

pymoysklad's Issues

Check how MetaInMeta serialization will work

For some meta object MoySklad have something like this
{ 'some_field_of_meta_type': {'meta': Meta()} }
while there is just normal meta object.
For this i implemented MetaInMeta object. Deserialization works perfectly, but we still need to check how serialization work.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.