Python library for generating e-invoices using GST's E-invoicing portal.
Project description
Python library for GST's E-invoicing portal
This is the python library for interacting with GST's E-invoicing portal.
Usage
Install the library:
pip install gst-e-invoicing
Use it in your code:
from gst_irn import Session, Invoice, InvoiceItem
with open('public_key.pem') as f:
public_key = f.read()
session = Session(
'GSTIN',
client_id='CLIENT_ID',
client_secret='CLIENT_SECRET',
username='USERNAME',
password='PASSWORD',
public_key=public_key,
is_sandbox=True,
)
session.generate_token()
# create invoice object
# use Session.get_party to automatically fetch details
# or use Party() to provide details manually
seller = session.get_party('SELLER_GSTIN')
buyer = session.get_party('BUYER_GSTIN')
items = [
InvoiceItem(
hsn_sac='HSN_SAC',
)
]
# provide document details for the invoice
invoice = Invoice(
no="DOC/0001",
dt=dt.date(2022, 5, 19),
items=items,
seller=seller,
buyer=buyer,
)
# submit and get the e-invoice
einvoice = session.generate_einvoice(invoice)
# access irn and qr-code
print(einvoice['Irn'])
# prints irn
# print qr-code
from gst_irn.qr import get_qr_code_image_html
qr_code_image = get_qr_code_image_html(einvoice['SignedQRCode'])
qr_code_image
# prints <img src="...">
Technical details
Schema Spec: https://www.cbic.gov.in/resources/htdocs-cbec/gst/notfctn-60-central-tax-english-2020.pdf Simplified Spec: https://einvoice1.gst.gov.in/Documents/EINVOICE_SCHEMA.xlsx
The key's used in JSON file are CamelCase. The attributes we use in the Python library are snake_case version of the same.
Development
Setting up dev environment:
# create and activate virtual env
python3 -m venv .venv
source .venv/bin/activate
# install requirements
pip install '.[dev]'
# provide credentials
cp .env.sample .env
# edit and update the credentials in .env file
vi .env
# running tests
python -m unittest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
gst-e-invoicing-0.1.0.tar.gz
(43.7 kB
view hashes)
Built Distribution
Close
Hashes for gst_e_invoicing-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60979c449161fd477d07e7c93d9962b61ef12699f4fe63cc3a81da881a792379 |
|
MD5 | c6fb59136da8464511ef4bef48d59e25 |
|
BLAKE2b-256 | d94d431963c79aeab99fe4afb009f0cb54d39c2fde995d9a5b5bebbc022d6ece |