Skip to main content

OAuth 2.0 / JWT authentication helpers for the Bling API v3

Project description

bling-jwt-auth-python

Repositório: github.com/tempont/bling-jwt-auth-python · PyPI: bling-jwt-auth

Biblioteca Python simples para autenticar na API v3 do Bling usando OAuth 2.0 e tokens JWT.

Ela ajuda a:

  • gerar a URL de autorização do Bling;
  • trocar o code recebido por tokens;
  • salvar os tokens em arquivo ou SQLite;
  • renovar o access token automaticamente quando necessário;
  • montar os headers corretos para chamar a API do Bling.

Versão em inglês: docs/README.en.md

Requisitos

  • Python 3.14 ou superior
  • Uma aplicação OAuth cadastrada no Bling

Instalação

Instale pelo pip:

pip install bling-jwt-auth

Ou instale direto do GitHub:

pip install "git+https://github.com/tempont/bling-jwt-auth-python.git"

Para desenvolvimento local neste repositório, use:

uv sync --extra dev

Configuração

Copie o arquivo de exemplo:

cp .env.example .env

Edite o .env com os dados da sua aplicação no Bling:

BLING_CLIENT_ID=seu_client_id
BLING_CLIENT_SECRET=seu_client_secret
BLING_REDIRECT_URI=https://seu-dominio.com/oauth/callback

Por padrão, os tokens são salvos em SQLite. Se quiser salvar em JSON:

BLING_TOKEN_STORE=file
BLING_TOKEN_STORE_PATH=./token.json

Como usar

1. Autorizar a conta Bling

Rode o exemplo de OAuth:

uv run python examples/oauth_flow.py

O script vai mostrar uma URL. Abra essa URL no navegador, autorize o acesso no Bling e cole no terminal o code recebido no callback.

Se quiser que o script tente abrir o navegador automaticamente:

uv run python examples/oauth_flow.py --open

2. Testar uma chamada autenticada

Depois de salvar o token, rode:

uv run python examples/authenticated_request.py

Esse exemplo usa o token salvo, renova se necessário e chama um endpoint de homologação do Bling.

3. Usar no seu código

import httpx
from bling_jwt_auth import (
    BlingAuthSettings,
    OAuthClient,
    TokenManager,
    bling_api_headers,
    create_token_store,
)

settings = BlingAuthSettings()
store = create_token_store(settings)

with OAuthClient(settings) as oauth:
    manager = TokenManager(oauth, store, settings)
    access_token = manager.get_access_token()

headers = bling_api_headers(access_token)

response = httpx.get(
    "https://api.bling.com.br/Api/v3/produtos",
    headers=headers,
)
response.raise_for_status()
print(response.json())

Comandos úteis para desenvolvimento

Rodar lint, checagem de tipos e testes:

make check

Ou:

bash scripts/check.sh

Rodar apenas os testes:

uv run --extra dev pytest

Licença

MIT. Veja LICENSE.

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

bling_jwt_auth-0.1.0.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

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

bling_jwt_auth-0.1.0-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file bling_jwt_auth-0.1.0.tar.gz.

File metadata

  • Download URL: bling_jwt_auth-0.1.0.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for bling_jwt_auth-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ce9da87c9857ef1026c54fe6d087814a4da7dadfd8497ff450e42cc0f9a93d50
MD5 a44bebfff679fc65b5aadad5186b4ec5
BLAKE2b-256 cda6f8d3daf0431777e4edb452176880aa9dfcc935ee8ca0730d6fcc630b42cf

See more details on using hashes here.

Provenance

The following attestation bundles were made for bling_jwt_auth-0.1.0.tar.gz:

Publisher: publish.yml on tempont/bling-jwt-auth-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bling_jwt_auth-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: bling_jwt_auth-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for bling_jwt_auth-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 545949b4d5130564484ccb53e07793fc793a0a8d9073c96a03216f77f673fb5c
MD5 9ef7700b40801f71909bbdb136b5b0fe
BLAKE2b-256 2e7510c81c35c4479b23912a343d807554b16b98fecf2994381a91721abece80

See more details on using hashes here.

Provenance

The following attestation bundles were made for bling_jwt_auth-0.1.0-py3-none-any.whl:

Publisher: publish.yml on tempont/bling-jwt-auth-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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