Skip to main content

Simple wrapper for Shopee Affiliate API.

Project description

SaAPI

:warning: Esse pacote não é oficial.

Um simples wrapper para a API de afiliados da Shopee[^1].

from saapi import SaAPI

client = SaAPI({
    "app_id": "seu_app_id",
    "secret": "seu_secret"
})
res = client.queries.product_offer_v2(
    {"keyword": "tênis"},
    {"nodes": ["itemId", "productName"]}
)

print(res)
# { "nodes": [
#    {'itemId': 22093519050, 'productName': 'Tênis Sapatênis Polo Masculino'},
#    ...
#   ]
# }

Todas as queries e mutations que não estão depreciados foram implementados, os campos que foram depreciados não foram implementados.

Downloads Supported Versions Contributors

Instalação

$ pip install saapi

Versão mínima do python 3.9.

Uso com tipos

Todas as operações possuem tipos para facilitar o uso e evitar erros, seja argumentos ou campos de retorno.

from saapi import SaAPI
from saapi.queries.product_offer_v2 import ProductOfferV2Node, ProductOfferV2SortType
from saapi.queries import PageInfoResParams

client = SaAPI({
    "app_id": "seu_app_id",
    "secret": "seu_secret"
})
res = client.queries.product_offer_v2(
    {
        "keyword": "blusa",
        "limit": 10,
        "sortType": ProductOfferV2SortType.COMMISSION_DESC
    },
    {
        "nodes": [
            ProductOfferV2Node.itemId,
            ProductOfferV2Node.productName,
            ProductOfferV2Node.offerLink
        ],
        "pageInfo": [
            PageInfoResParams.hasNextPage
        ]
    }
)

Lidando com erros

import logging
from saapi import SaAPI
from saapi.errors import SaAPIError, SaAPIErrorCode

client = SaAPI({
    "app_id": "seu_app_id",
    "secret": "seu_secret"
})
try:
    res = client.queries.product_offer_v2({},{"nodes": [...]})
    # seu código
except SaAPIError as err:
    if err.extensions["code"] == SaAPIErrorCode.IDENTITY_AUTHENTICATION_ERROR:
        logging.exception(err.message)
    else:
        logging.exception("algo deu errado")

Outros países

Caso as credenciais sejam de outro país, é possível configurar:

from saapi import SaAPI
from saapi.countries import Country

client = SaAPI({
    ...,
    "country": Country.INDONESIA
})

Desenvolvimento

Faça um clone, configure um ambiente virtual e instale pip install --editable .[all]. Para fazer testes você deve utilizar o comando tox. Tenha em mente que para testar em todas as versões você precisa tê-las instaladas e com acesso global/local. Particularmente utilizei o asdf[^2] para isso.

[^1]: Documentação. É preciso estar logado para visualizar a documentação. [^2]: asdf

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

saapi-0.2.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

saapi-0.2-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file saapi-0.2.tar.gz.

File metadata

  • Download URL: saapi-0.2.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for saapi-0.2.tar.gz
Algorithm Hash digest
SHA256 3ef7bbd91e09444ca3e8aa6f808244d035c235025c72138b1cca83fb9c3bdf20
MD5 86b73480a66a6e3755f0350309d0facc
BLAKE2b-256 1111bf786cfade4f3581aaa7c094b93638c591c502988504459bf592e7b2f73b

See more details on using hashes here.

File details

Details for the file saapi-0.2-py3-none-any.whl.

File metadata

  • Download URL: saapi-0.2-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for saapi-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 00e07664f2fac9ab6d69751f9a35431f060de5dac088eecfa87600e0e7187dac
MD5 16408ce7634b02fd5b2eed00539b18f3
BLAKE2b-256 67cce52040f27e8e66c10b013768c4f8d4e0957d4709a4c32027237ce7614393

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page