Skip to main content

anaf-sync

CI Coverage PyPI version Python versions

Scheduled local archiver for RO e-Factura invoices, built on anafpy. Each run lists every message in ANAF's 60-day retention window, downloads the ones it hasn't seen before, and files them under paths rendered from a template of invoice variables. Runs on Windows, Linux, and macOS.

Design rationale lives in DESIGN.md; conventions for working on the codebase in CLAUDE.md.

Install

uv tool install anaf-sync        # from a published wheel
# or, from this checkout:
uv tool install --from . anaf-sync

Authentication

anaf-sync reuses the anafpy login — the same one the anafpy MCP server uses:

  1. anafpy auth login (browser OAuth with your ANAF certificate) writes the token set to the OS credential store (or a JSON file).
  2. Set ANAFPY_CLIENT_ID and ANAFPY_CLIENT_SECRET in the environment (or a .env file) so scheduled runs can refresh expired tokens.

Optional, mirroring anafpy: ANAFPY_TOKEN_STORE_BACKEND=file and ANAFPY_TOKEN_STORE=~/.anafpy/tokens.json for headless hosts without a credential store.

Configure

anaf-sync init            # writes a commented config.toml
anaf-sync status          # shows where it lives on your platform

The interesting part is the path template:

[output]
directory = "~/Facturi"
template  = "{cif}/{direction}/{issue_date:%Y}/{issue_date:%m}/{issue_date:%Y-%m-%d}_{number}_{partner_name}"
artifacts = ["zip", "pdf"]        # also: xml, signature, metadata

Templates use Python format syntax over the invoice's context: number, issue_date / due_date (real dates — strftime specs work), currency, total, kind, direction, cif, seller_name/seller_cif, buyer_name/buyer_cif, partner_name/partner_cif (the other party), message_id, request_id, message_type, created. Substituted values are sanitised for the filesystem; literal / in the template creates folders; each artifact appends its own extension.

Run

anaf-sync sync --dry-run   # see what would be downloaded
anaf-sync sync             # download everything new

Runs are idempotent: a state file records archived message ids, so overlapping 60-day windows never duplicate work, and anything ANAF is about to purge has already been captured.

Schedule

anaf-sync schedule install --every 6h        # or --daily-at 07:30
anaf-sync schedule status
anaf-sync schedule remove

This registers the sync with the OS scheduler — Task Scheduler on Windows, a systemd user timer on Linux (loginctl enable-linger $USER to run while logged out), launchd on macOS. No daemon of its own.

Development

uv sync
uv run pytest
uv run ruff check src tests && uv run black --check src tests && uv run mypy src

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

anaf_sync-0.1.0.tar.gz (84.8 kB view details)

Uploaded Source

Built Distribution

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

anaf_sync-0.1.0-py3-none-any.whl (20.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: anaf_sync-0.1.0.tar.gz
  • Upload date:
  • Size: 84.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for anaf_sync-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f3d54f2c9e2135cc5972e081f1553a03b4c296b2166db5db0e2b1f9c29905b7b
MD5 d7224684c7aa86c41a0d2d4482d5a0c0
BLAKE2b-256 e49d116d41c06981e0b4b218302c5be3abbdaa77dbf1f3699d247ccd9e3003d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for anaf_sync-0.1.0.tar.gz:

Publisher: release.yml on robert-malai/anaf-sync

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: anaf_sync-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 20.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for anaf_sync-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 65a75722f00d3e3d5745e4465a05581b81c87a9b666c9cc1da820f411370257f
MD5 b780ff9c46cb813617aa33ce15f41a35
BLAKE2b-256 8e2a1efcf2e504be1f64e610a73212fdd40c842ce4ed8bb0994aaac17f4eea2c

See more details on using hashes here.

Provenance

The following attestation bundles were made for anaf_sync-0.1.0-py3-none-any.whl:

Publisher: release.yml on robert-malai/anaf-sync

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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