IFirma API client
Project description
Python wrapper for ifirma's API
Requires Python 3.8
or later.
This little project aims to refresh my python coding skills.
Besides coding fun this code also supported invoicing in a few small online shops. It does its job pretty well.
First version was inspired of @DariuszAniszewski's python-ifirma but covers slightly different operations.
Features
It supports following operations
- create invoice (VAT & non-VAT payers)
- listing invoices created in past
- send email with pdf-invoice attached (it sends also copy to the account owner)
- parses invoice described with yaml file
- download invoice in pdf format
Getting started
pip install pnowosie.ifirma-api
or from this repository
pip install -e git+git@github.com:pnowosie/ifirma-api.git#egg=pnowosie.ifirma-api
Invoice creation
Please review examples in ./sample_invoice
directory. You will find there how to create invoice from yaml file.
Send it via email and download pdf version to a location of choice.
Or create invoice from code
from ifirma.invoice import (Invoice, Customer, InvoicePosition, INVOICE_TYPE)
invoice = Invoice(
invoice_type=INVOICE_TYPE.NON_VAT_PAYER,
issue_date=datetime(...)
).with_issuer(
'Imię Nazwisko'
).with_payed(
float(price)
).with_comments(
f"Nr zamówienia: {numer}"
).with_position(
InvoicePosition(product_name, float(price))
).with_new_customer(
Customer(full_name, email, zip, city, street1, street2)
)
if you registered your customer in ifirma
you can use
invoice.with_known_customer(
name, tax_id
)
Having invoice object, we can send it to create an invoice in the ifirma. Please mind that two environment variables IFIRMA_API_USERNAME and IFIRMA_API_KEY have to be set to authenticate API request.
import ifirma.api as Api
create_invoice_response = Api.create_invoice(invoice)
if create_invoice_response.success:
print(f"Invoice created with id {create_invoice_response}")
else:
print("Something bad has happened: " + create_invoice_response.message)
Next step can be send an email with the invoice attached to the customer email address. CC is delivered also to our address registered in the ifirma.
import ifirma.api as Api
custom_message = "Can you please send me more money? I'm getting ambitious vacation plans!"
email_send_response = Api.email_invoice(invoice_id, customer_email_address, custom_message)
If the pdf copy of the invoice is needed to be stored, we can download it as well
import ifirma.api as Api
from pathlib import Path
file_path = Path('/tmp') / f"invoice_{invoice_id}.pdf"
Api.download_invoice(invoice_id, file_path)
Please check this example.
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
Built Distribution
Hashes for pnowosie.ifirma-api-1.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 355819e17bcf50962b28c83748f55dfa5d925b6f148301cd0aadc115a0936fba |
|
MD5 | eac1b8ddea97d12b68e843e4af4d8fc0 |
|
BLAKE2b-256 | a2c5ad518fd1d0fbcc992d84d89fb54854c531b18373e902470edb12864c1435 |
Hashes for pnowosie.ifirma_api-1.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52b5d57bb0a8c81627ed44c464557e0aeecc7383b4b91c0a53defe5482874290 |
|
MD5 | b097e1040cf5d6c036df98ea15a8e1da |
|
BLAKE2b-256 | aed2a83d41d9c5b304c1c07ae339adbf79466ee1af0abfe760ceb8427f4cbb39 |