Skip to main content

Smartbill Connector

Project description

smartbill.py

The smartbill.py package is a Python client (wrapper) for smartbill.hu::Számla Agent.

Introduction

Számla Agent is a non-browser-based interface of the Számlázz.hu system. It receives XML messages and depending on the received information it can do various actions.

Using smartbill.py, you can interact with this interface in a convenient and Pythonic way.

smartbill.py provides multiple translated (Hungarian -> English) NamedTuple classes to help interaction with the API client.

Integration

Install the package from PyPI:

pip install smartbill.py

Import the client into your Python module:

from smartbill import SmartbillClient

# Depending on your future action(s), you might need the following model classes too:
from smartbill import Header, Merchant, Buyer, Item, PdfDataMissingError

For all model classes, see models.py.

API

The SmartbillClient instance can be initialised in two ways:

  • username/password combination
  • Agent Key (Számla Agent Kulcs)

Failing to provide one of these authentication methods will raise AssertionError.

All actions (e.g.: generate_invoice, reverse_invoice, etc.) return a new SmartbillResponse instance.
smartbillResponse has the following major parameters:

  • .has_errors
  • .error_code
  • .error_message
  • .ok
  • .response
  • .text

smartbillResponse has the following major functions:

  • .get_pdf_base64()
  • .get_pdf_bytes()
  • .write_pdf_to_disk()
  • .print_errors()

For more details, see the contents of class smartbillResponse.

Implementation Status

Currently, the following actions can be executed via smartbill.py:

  • create invoices
  • reverse invoices
  • register credit entries
  • query invoice pdf files
  • query invoice xml files
  • delete pro forma invoices
  • create receipts // With limitations. See the source code for more details
  • reverse receipts
  • query receipts
  • send receipts
  • query taxpayers
  • self billing // Implementation is not on the roadmap

Note: New actions are continuously implemented. Contributions are welcome too.

Each action's function takes a definite number of arguments. For example, let's examine smartbillClient.generate_invoice():

from typing import List
from smartbill.models import Header, Merchant, Buyer, Item, smartbillResponse

def generate_invoice(header: Header,
                     merchant: Merchant,
                     buyer: Buyer,
                     items: List[Item],
                     e_invoice: bool = True,
                     invoice_download: bool = True,
                     ) -> smartbillResponse:
    pass

The smartbill.hu::Számla Agent XML has the following tags (depending on the action):

<xmlszamla>
    <beallitasok></beallitasok>
    <fejlec></fejlec>
    <elado></elado>
    <vevo></vevo>
    <tetelek>
        <tetel></tetel>
    </tetelek>
</xmlszamla>

Each of these tags, except <beallitasok> and <tetelek> can be mapped to a dataclass model:

  • fejlec -> Header
  • elado -> Merchant
  • vevo -> Buyer
  • tetel -> Item

Use the models to create your payloads for each action, for example, to create a <fejlec>:

from smartbill.models import Header

fejlec = Header(
    creating_date="2021-08-26",
    payment_date="2021-08-26",
    due_date="2021-08-31",
    payment_type="Átutalás",
    currency="HUF",
    invoice_language="hu",
    invoice_comment="No Comment",
    name_of_bank="MNB",
    exchange_rate=0.0,
    order_number="ORDER-73",
    pro_forma_number_ref="",
    deposit_invoice=False,
    invoice_after_deposit_invoice=False,
    correction_invoice=False,
    number_of_corrected_invoice="",
    proforma_invoice=False,
    invoice_prefix="DK",
)

This Header dataclass instance can be passed to the generate_invoice function:

resp = generate_invoice(header=fejlec)

Contribution

Contributions are welcome. Should you have a question or an idea, open a new GitHub issue. Your contributions are expected through GitHub Pull Requests.

If you're developing with PyCharm, consider using examples/IntelliJ Config Template.run.xml to configure the examples (demo files) for quick testing.

Releasing

Releases are automatically pushed from the master branch on a new tag using GitHub Workflows.

Manual Releasing
Make sure you have the latest version of PyPA’s build installed:

python -m pip install --upgrade build

Run this command from the same directory where pyproject.toml is located:

python setup.py sdist bdist_wheel

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

smartbill_py-0.0.6.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

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

Smartbill.py-0.0.6-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file smartbill_py-0.0.6.tar.gz.

File metadata

  • Download URL: smartbill_py-0.0.6.tar.gz
  • Upload date:
  • Size: 16.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.0

File hashes

Hashes for smartbill_py-0.0.6.tar.gz
Algorithm Hash digest
SHA256 4b5263af1aefd7fe18f05825630f93157d78fe3475c507c0727cfe9e2b022efa
MD5 606d989f7211827a7d9f41cb921263cc
BLAKE2b-256 da535b52d72fe8d91323fd3c741d41a375eb4b3afa8a65b1c31cd79d98aba942

See more details on using hashes here.

File details

Details for the file Smartbill.py-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: Smartbill.py-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 18.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.0

File hashes

Hashes for Smartbill.py-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 35609224bd03840ef7c41a5a96fcd0bc9c63aa0474d293dc8049827bf0d54e49
MD5 fc4684589ad6969fbebb4631cf9ee782
BLAKE2b-256 098d9194a2ebc00606329b995a167444d7c54bb308e51e53806fe5f7c04bf70b

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