Skip to main content

Python SDK for Cetustek Taiwan e-invoice API

Project description

Cetustek

PyPI version Python License: MIT

A Python SDK for the Cetustek Taiwan e-invoice API.

Features

  • Create, query, and cancel e-invoices
  • Type-safe with dataclass request/response models
  • Comprehensive error handling with custom exceptions
  • Full support for B2B and B2C invoices

Installation

pip install cetustek

Requirements: Python 3.9+

Quick Start

from cetustek import Cetustek, CreateInvoiceInput, InvoiceItem

client = Cetustek(
    endpoint="https://invoice.cetustek.com.tw/InvoiceMultiWeb/InvoiceAPI",
    rent_id="YOUR_RENT_ID",
    site_code="YOUR_SITE_CODE",
    api_password="YOUR_API_PASSWORD",
)

result = client.createInvoice(CreateInvoiceInput(
    order_id="12345678",
    order_date="2026/01/15",
    donate_mark="0",
    invoice_type="07",
    tax_type="1",
    pay_way="1",
    items=[InvoiceItem(
        production_code="PROD001",
        description="Product",
        quantity=1,
        unit_price=1000,
    )],
))

print(result.invoice_number)  # "WP20260002"
print(result.random_code)     # "6827"

Usage

Create Invoice

from cetustek import CreateInvoiceInput, InvoiceItem, CetustekAPIError

try:
    result = client.createInvoice(CreateInvoiceInput(
        order_id="12345678",
        order_date="2026/01/15",
        donate_mark="0",              # 0: No donation, 1: Donate, 2: Donate to NPO
        invoice_type="07",            # 07: B2B, 08: B2C
        tax_type="1",                 # 1: Taxable, 2: Zero-rated, 3: Tax-free
        pay_way="1",
        items=[InvoiceItem(
            production_code="PROD001",
            description="Product description",
            quantity=1,
            unit_price=1000,
            unit="件",                # Optional
        )],
        # Optional buyer info
        buyer_identifier="12345678",  # Tax ID (統一編號)
        buyer_name="Company Name",
        buyer_email="email@example.com",
        tax_rate=0.05,                # Default: 5%
    ))

    print(result.invoice_number)      # "WP20260002"
    print(result.random_code)         # "6827"
    print(result.invoice_year)        # "2026" (derived property)

except CetustekAPIError as e:
    print(f"Error: {e.code}")

Query Invoice

from cetustek import QueryInvoiceInput

result = client.queryInvoice(QueryInvoiceInput(
    invoice_number="WP20260002",
    invoice_year="2026",
))

print(result.order_id)
print(result.buyer_name)
print(result.total_amount)
print(result.invoice_status)

Cancel Invoice

from cetustek import CancelInvoiceInput

result = client.cancelInvoice(CancelInvoiceInput(
    invoice_number="WP20260002",
    invoice_year="2026",
    remark="Cancellation reason",
))

if result.success:
    print("Invoice cancelled")
else:
    print(f"Failed: {result.code}")

API Reference

Client

Parameter Description
endpoint Cetustek API endpoint URL
rent_id Rent ID (統一編號)
site_code Site code
api_password API password

Response Models

CreateInvoiceResponse

Field Type Description
invoice_number str Invoice number (e.g., "WP20260002")
random_code str 4-digit random code
invoice_year str Year (derived from invoice_number)

QueryInvoiceResponse

Field Type Description
invoice_number str Invoice number
order_id str Order ID
random_code str Random code
buyer_identifier str Buyer tax ID
buyer_name str Buyer name
seller_identifier str Seller tax ID
seller_name str Seller name
invoice_status str Status
sales_amount float Sales amount
tax_amount float Tax amount
total_amount float Total amount
raw_xml str Raw XML response

CancelInvoiceResponse

Field Type Description
success bool Whether cancellation succeeded
code str Response code ("C0" = success)
message str Error message (if failed)

Input Models

InvoiceItem

Field Type Required Description
production_code str Yes Product code
description str Yes Description
quantity float Yes Quantity
unit_price float Yes Unit price
unit str No Unit (e.g., "件")

CreateInvoiceInput

Field Type Required Description
order_id str Yes Order ID
order_date str Yes Date (yyyy/MM/dd)
donate_mark str Yes 0/1/2
invoice_type str Yes 07 (B2B) / 08 (B2C)
pay_way str Yes Payment method
tax_type str Yes 1/2/3/4/5/9
items List Yes Invoice items
buyer_identifier str No Buyer tax ID
buyer_name str No Buyer name
buyer_email str No Buyer email
tax_rate float No Tax rate (default: 0.05)
carrier_type str No Carrier type
carrier_id1 str No Carrier ID
npoban str No NPO code

Error Handling

from cetustek import CetustekError, CetustekAPIError

try:
    result = client.createInvoice(invoice_input)
except CetustekAPIError as e:
    print(f"API Error: {e.code} - {e.message}")
except CetustekError as e:
    print(f"SDK Error: {e}")

Example

See example.py for a complete working example.

Getting Started

pip install cetustek
from cetustek import Cetustek, CreateInvoiceInput, InvoiceItem

# Initialize client
client = Cetustek(
    endpoint="https://invoice.cetustek.com.tw/InvoiceMultiWeb/InvoiceAPI",
    rent_id="YOUR_RENT_ID",
    site_code="YOUR_SITE_CODE",
    api_password="YOUR_API_PASSWORD",
)

# Create an invoice
result = client.createInvoice(CreateInvoiceInput(
    order_id="12345678",
    order_date="2026/01/15",
    donate_mark="0",
    invoice_type="07",
    tax_type="1",
    pay_way="1",
    items=[InvoiceItem(
        production_code="PROD001",
        description="Product",
        quantity=1,
        unit_price=1000,
    )],
))

print(result.invoice_number)  # e.g., "WP20260002"
print(result.random_code)     # e.g., "6827"

License

MIT

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

cetustek-1.0.1.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

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

cetustek-1.0.1-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file cetustek-1.0.1.tar.gz.

File metadata

  • Download URL: cetustek-1.0.1.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cetustek-1.0.1.tar.gz
Algorithm Hash digest
SHA256 fb73457e4c26a9a9b993e9dc46d424f7d5a71830abc22b1bce939b8b47334d08
MD5 a0f0ea1d28ef8808b2bad8b5fe63b5b3
BLAKE2b-256 29d9a577acd87c4fe8b48f5620f7c3726312f524da491898beafdd36c805c9c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for cetustek-1.0.1.tar.gz:

Publisher: publish.yml on alon21034/cetustek-sdk

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

File details

Details for the file cetustek-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: cetustek-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cetustek-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2591c692db20c36cf4731e3bbeeecd5b31fdef3db5b1f13b10eab611cfb33bff
MD5 010363e1d22ea33ece25324b40547a82
BLAKE2b-256 696cf0c6a985dae4c1e45365b8760a61d7e141f0c523905f11a6253f08cecd76

See more details on using hashes here.

Provenance

The following attestation bundles were made for cetustek-1.0.1-py3-none-any.whl:

Publisher: publish.yml on alon21034/cetustek-sdk

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