Skip to content

Make xsdata optional and add requests-only fallback in FiscalClient#21

Merged
rvalyi merged 1 commit intomainfrom
codex/add-soft-dependency-for-xsdata
Mar 11, 2026
Merged

Make xsdata optional and add requests-only fallback in FiscalClient#21
rvalyi merged 1 commit intomainfrom
codex/add-soft-dependency-for-xsdata

Conversation

@rvalyi
Copy link
Copy Markdown
Member

@rvalyi rvalyi commented Mar 8, 2026

Motivation

  • Reduce friction for consumers by making xsdata a soft (optional) dependency so basic users need only requests + requests-pkcs12.
  • Allow FiscalClient to perform basic SOAP requests using plain XML when xsdata is not installed, increasing adoption for lightweight use-cases.
  • Preserve existing behavior and compatibility for projects that do use xsdata (nfelib / Odoo integrations) by keeping parsing/databinding unchanged when available.

Description

  • Remove xsdata from mandatory dependencies and expose it as an optional extra xsdata in pyproject.toml, and document the optional extra and a requests-only usage example in README.md.
  • Add runtime detection (importlib.util.find_spec) and conditional imports so the module can operate with or without xsdata, providing lightweight fallback classes and exceptions when missing.
  • Implement a requests-based fallback in FiscalClient that uses requests.Session when xsdata is unavailable, including helpers _session, _post, prepare_headers, and _webservice_name, and a _xsdata_available flag to route behavior.
  • Adjust prepare_payload/send to accept raw XML payloads (str/bytes or {'raw_xml': ...}) in no-xsdata mode and to return the raw SOAP XML response when parsing is not available; update tests to cover the fallback behavior.

Testing

  • Ran ruff check brazil_fiscal_client tests and the code style/lint checks passed.
  • Compiled the package sources with python -m compileall brazil_fiscal_client tests and compilation succeeded.
  • Ran pytest -q in this environment but test collection failed because the optional test dependency nfelib is not installed here (this is unrelated to the change and affects collection of xsdata-dependent tests).
  • Added automated tests for the no-xsdata fallback in tests/test_fiscal_client.py, and a small automated smoke check invoking FiscalClient in requests-only mode completed successfully in this environment.

Codex Task

@rvalyi rvalyi force-pushed the codex/add-soft-dependency-for-xsdata branch from d44a378 to 833255b Compare March 11, 2026 03:10
@rvalyi rvalyi merged commit 80ce783 into main Mar 11, 2026
7 checks passed
@ak-git-bot ak-git-bot deleted the codex/add-soft-dependency-for-xsdata branch March 11, 2026 03:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants