Skip to main content

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

When you add more? Are PRs welcomed?

Probably never. It's here to support my business. If you're looking for ideas how to extend it, 👉 see issue #8

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

pnowosie.ifirma-api-1.2.0.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

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

pnowosie.ifirma_api-1.2.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file pnowosie.ifirma-api-1.2.0.tar.gz.

File metadata

  • Download URL: pnowosie.ifirma-api-1.2.0.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.2

File hashes

Hashes for pnowosie.ifirma-api-1.2.0.tar.gz
Algorithm Hash digest
SHA256 3c43815783c9491ec8f3765c518f7dfe57ee53f3934079e51af8bc35af2a7f72
MD5 6ca9d532f95245ec09213ca3fbd65ca8
BLAKE2b-256 4f824de4406ba4e16d08a0214c4ad05e1773d68f2671a121deb68820ed0a567a

See more details on using hashes here.

File details

Details for the file pnowosie.ifirma_api-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: pnowosie.ifirma_api-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.2

File hashes

Hashes for pnowosie.ifirma_api-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a026b8932375ca6ed44a8204e494473975555bd3d60e8700666f2b54b7b73348
MD5 e8ba4256a824a6141eafbdc560634af8
BLAKE2b-256 1b2ea1f372972749a4611b9b836d92aa7f18e84398c8043299b980537bd04da9

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