Skip to main content

SaAPI

:warning: Esse pacote não é oficial.

Um simples wrapper para a API de afiliados da Shopee1.

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 asdf2 para isso.

  1. Documentação. É preciso estar logado para visualizar a documentação. ↩

  2. asdf ↩

Metadata

Release files for saapi 0.2

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

Source distribution (sdist)

Source distribution for saapi 0.2
File Size Uploaded
saapi-0.2.tar.gz 13.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for saapi 0.2
File Interpreter ABI Platform
saapi-0.2-py3-none-any.whl Python 3 none any Details

Total release size: 28.1 kB

Release files / saapi-0.2.tar.gz

Download URL saapi-0.2.tar.gz
Size 13.7 kB
Tags Source
SHA-256 checksum
How to use checksums
3ef7bbd91e09444ca3e8aa6f808244d035c235025c72138b1cca83fb9c3bdf20
BLAKE2b-256 checksum
How to use checksums
1111bf786cfade4f3581aaa7c094b93638c591c502988504459bf592e7b2f73b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release files / saapi-0.2-py3-none-any.whl

Download URL saapi-0.2-py3-none-any.whl
Size 14.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
00e07664f2fac9ab6d69751f9a35431f060de5dac088eecfa87600e0e7187dac
BLAKE2b-256 checksum
How to use checksums
67cce52040f27e8e66c10b013768c4f8d4e0957d4709a4c32027237ce7614393
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release history Release notifications | RSS feed

This release

0.2 This release

2 release files

0.1

2 release files

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