Skip to main content

xsdata-rootfinder

A Python package designed to analyze Python source files and identify root models. This package supports different model types, including dataclass, Pydantic, and attrs, making it easy to work with various schema formats.

Features

  • Single File Analysis: Identify root models from a single Python source file.
  • Batch Processing: Analyze multiple files or directories with support for recursion.
  • Model Types: Supports dataclasses, Pydantic models, and attrs classes.
  • Multiprocessing: Optional multiprocessing for faster batch analysis.

Installation

To install xsdata-rootfinder, run the following command:

pip install xsdata-rootfinder

How It Works

The xsdata-rootfinder package analyzes Python source files to identify root models. A root model is defined as a class that is present in a file but not referenced within it. This is specifically desinged for models generated by xsdata but theoretically could be used for any models.

Any number of files or paths can be passed as arguments to the root_finders function. One caveat is that all files passed must reflect the layout of the codebase they exist in. This is important so as to accurately match any local import to the correct python file.

Drawbacks

There are two edge cases that are not taken into account within the logic. Thus, there could be inaccurate results. These issues will be patched up in the next release.

  1. Importing from a PYTHONPATH Module
    • Any file that imports models from a directory that is included in the PYTHONPATH variable.
  2. Import Forwarding Models
    • Any file that imports models from files that are import forwarding (i.e. not importing them from where they are defined).

Functionality Overview

root_finder

Analyze a single Python source file to find root models.

def root_finder(source: CodeOrStrOrPath, xsd_models: XsdModels = "dataclass") -> Optional[List[RootModel]]:
    ...
  • Arguments:
    • source: Python source to analyze (code string, file path, or path-like object).
    • xsd_models: Specifies model type ('dataclass', 'pydantic', or 'attrs').
  • Returns: List of root models or None.

Example Usage

from xsdata_rootfinder import root_finder

roots = root_finder("path/to/source.py", xsd_models="pydantic")

root_finders

Analyze a single directory or multiple files/directories to find root models. If a collection is passed, then each item in that collection must be a string or Path object representing an existing file or directory.

def root_finders(
    sources: Union[StrOrPath, Collection[StrOrPath]],
    xsd_models: XsdModels = "dataclass",
    directory_walk: bool = False,
    ignore_init_files: bool = True,
    multiprocessing: Optional[MultiprocessingSettings] = None,
) -> Optional[List[RootModel]]:
    ...
  • Arguments:
    • sources: One or more paths to analyze.
    • xsd_models: Specifies model type ('dataclass', 'pydantic', or 'attrs').
    • directory_walk: Boolean indicating a recursive search of directories.
    • ignore_init_files: Boolean indicating whether to ignore __init__.py files.
    • multiprocessing: Settings for parallel file processing.
  • Returns: List of root models or None.

Example Usage

from xsdata_rootfinder import root_finders

roots = root_finders(
    ["path/to/source1.py", "path/to/source2.py"],
    xsd_models="attrs",
    directory_walk=True,
    multiprocessing=None
)

License

This project is licensed under the terms of the MIT License.

Workflow Details

GitHub Actions automate CI/CD workflows, including tests and package deployment.

Metadata

Release files for xsdata-rootfinder 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xsdata-rootfinder 0.1.0
File Size Uploaded Provenance Actions
xsdata_rootfinder-0.1.0.tar.gz 13.6 kB Without provenance Details for xsdata_rootfinder-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for xsdata-rootfinder 0.1.0
File Interpreter ABI Platform Actions
xsdata_rootfinder-0.1.0-py3-none-any.whl Python 3 none any Details for xsdata_rootfinder-0.1.0-py3-none-any.whl

Total release size: 26.9 kB

Release files / xsdata_rootfinder-0.1.0.tar.gz

Download URL xsdata_rootfinder-0.1.0.tar.gz
Size 13.6 kB
Tags Source
SHA-256 checksum
How to use checksums
95cf4be1a6afa0461f0a265c58bbd7cb419919c8d6b696b42ef9004e9f5dd807
BLAKE2b-256 checksum
How to use checksums
8e31dad1cd3f3ef6b5c7a78c7218efa759936bad6992b0d59583b7dfd7a9d7bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.0.1 CPython/3.12.1 Windows/11

Release files / xsdata_rootfinder-0.1.0-py3-none-any.whl

Download URL xsdata_rootfinder-0.1.0-py3-none-any.whl
Size 13.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ef7d75f0b45cdb8ad3dd695e529c5a467a0ad37518cacd380fc3ed68ec903cf6
BLAKE2b-256 checksum
How to use checksums
fef225d5ece82aac96af66f5e9ad1350d2642f06648b77f2388bc24abcb485e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.0.1 CPython/3.12.1 Windows/11

Security for xsdata-rootfinder 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page