Skip to main content

Python library for wFirma API with synchronous and asynchronous support

Project description

python-wfirma

Python client for the wFirma accounting API. Supports both synchronous and asynchronous usage.

Status: Alpha (v0.1.0). The API surface may change before 1.0.

Installation

pip install python-wfirma

Or with uv:

uv add python-wfirma

Usage

API Key Authentication

from wfirma.sync.auth import APIKeyAuth
from wfirma.sync.client import WFirmaClient

auth = APIKeyAuth(
    access_key="your_access_key",
    secret_key="your_secret_key",
    app_key="your_app_key",
)

with WFirmaClient(auth=auth, company_id=123) as client:
    contractor = client.contractors.add(name="ACME Sp. z o.o.", nip="1234567890")

    invoice = client.invoices.add(
        invoice={
            "contractor_id": contractor.id,
            "type": "normal",
            "paid": "0",
        }
    )

    invoices = client.invoices.find()

Async

import asyncio
from wfirma.async_.auth import APIKeyAuth
from wfirma.async_.client import WFirmaClient


async def main() -> None:
    auth = APIKeyAuth(
        access_key="your_access_key",
        secret_key="your_secret_key",
        app_key="your_app_key",
    )

    async with WFirmaClient(auth=auth, company_id=123) as client:
        contractor = await client.contractors.add(
            name="ACME Sp. z o.o.", nip="1234567890"
        )
        invoices = await client.invoices.find()


asyncio.run(main())

OAuth 2.0

from wfirma.sync.auth import OAuth2Auth
from wfirma.sync.client import WFirmaClient
from wfirma.config import Environment

oauth = OAuth2Auth(
    client_id="your_client_id",
    client_secret="your_client_secret",
    redirect_uri="https://yourapp.example.com/callback",
    environment=Environment.PRODUCTION,
)

# Step 1: redirect user to authorization URL
url = oauth.build_authorization_url(scope="invoices-read")

# Step 2: exchange the code from callback
token = oauth.exchange_code(code="authorization_code_from_callback")

# Step 3: use the client
with WFirmaClient(auth=oauth, company_id=123) as client:
    invoices = client.invoices.find()

Configuration

The library reads credentials from environment variables when using from_env() class methods:

# .env
WFIRMA_APP_KEY=your_app_key
WFIRMA_APP_SECRET=your_app_secret
WFIRMA_ENVIRONMENT=sandbox  # or production
WFIRMA_COMPANY_ID=123
from wfirma import get_config

config = get_config()
print(config.base_url)  # https://sandbox-api2.wfirma.pl

Supported Resources

The client exposes the following wFirma API resources. Each resource provides methods matching the upstream API (typically add, find, get, edit, delete):

Core: invoices, contractors, goods, payments, expenses, documents

Company: company, company_accounts, company_packs

Declarations: declaration_countries, declaration_body_jpkvat, declaration_body_pit

Warehouse: warehouses, warehouse documents (PW, PZ, R, RW, WZ, ZD, ZPD, ZPM)

Reference data: tags, series, terms, term_groups, vat_codes, translation_languages, taxregisters, interests, ledger_accountant_years, ledger_operation_schemas

Users & misc: users, user_companies, vehicles, vehicle_run_rates, payment_cashboxes, invoice_deliveries, invoice_descriptions, notes, webhooks

Development

Requires Python 3.12+. The project uses uv for dependency management.

git clone https://github.com/dekoza/python-wfirma.git
cd python-wfirma
uv venv && uv sync --extra dev
uv run pre-commit install

Tests

uv run pytest                                     # all tests
uv run pytest --cov=wfirma --cov-report=html      # with coverage
uv run pytest -n auto                             # parallel

Linting & type-checking

uv run ruff format src tests
uv run ruff check --fix src tests
uv run mypy src

Contributing

See CONTRIBUTING.md.

License

MIT — see LICENSE.


This library is not affiliated with wFirma. It is an independent project. Built on httpx, Pydantic, and authlib.

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

python_wfirma-0.1.0.tar.gz (203.5 kB view details)

Uploaded Source

Built Distribution

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

python_wfirma-0.1.0-py3-none-any.whl (151.1 kB view details)

Uploaded Python 3

File details

Details for the file python_wfirma-0.1.0.tar.gz.

File metadata

  • Download URL: python_wfirma-0.1.0.tar.gz
  • Upload date:
  • Size: 203.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for python_wfirma-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7362bec621b232f53498df44e294d90ba5e0ffb831b7052cb74ff55cf9142145
MD5 b2bd538f2852b94092a8afe9c5e46965
BLAKE2b-256 98638ebc1f17c7a21ea6fc56f0d4fe89d47beb5be6332ac3da2d777872206191

See more details on using hashes here.

File details

Details for the file python_wfirma-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: python_wfirma-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 151.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for python_wfirma-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a1a4d7baed32abf8a3e4622a1224c5e9287f4ad4c601e755b0a4474bb77a8820
MD5 968743e05f51bb6987c2ca44458d5024
BLAKE2b-256 157d2e7f00d495d2af6b6ae774ed12577df013692a4d76c5702bb0d1f64e5abd

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