Skip to main content

CDISC Define-XML v2.1 utilities

Project description

defineutils

CDISC Define-XML v2.1 utilities

The defineutils package currently includes 2 modules:

  1. definehtml.py: transforms a define.xml into a define.html using the stylesheet
  2. validate.py: schema validates a define.xml file

The definehtml.py module includes the Define-XML v2.1 style sheet to simplify usage. It generates a define.html file, or alternatively will generate an HTML string.

The validate.py module includes the Define-XML v2.1 schema to simplify usage. It schema validates a define.xml file and returns a define.xml is valid message to indicate success, or a detailed message documenting the schema validation issues.

Using defineutils

Currently, defineutils contains 2 modules, one for generating an HTML rendition and one for schema validation.

Example code used to generate a define.html from a define.xml:

from pathlib import Path
from defineutils.definehtml import DefineHtml, DefineHtmlGenerationError

out_file = Path(__file__).parent.joinpath("define.html")
dh = DefineHtml(Path(__file__).parent.joinpath("define.xml"))
dh.transform_to_html_file(out_file)

The above code applies the Define-XML v2.1 stylesheet to the define.xml to generation the define.html file. The stylesheet is embedded in the module. For error handling, use the custom DefineHtmlGenerationError exception.

Example code used to schema validate a define.xml:

from pathlib import Path
from defineutils.validate import DefineSchemaValidator, DefineSchemaValidationError

validator = DefineSchemaValidator(Path(__file__).parent.joinpath("define.xml"))
try:
    result = validator.validate_define_file()
except DefineSchemaValidationError as e:
    print(e)

The above code schema validates the specified define.xml file. The Define-XML v2.1 schema is embedded into the module. The schema validation errors are reported via the DefineSchemaValidationError exception.

Running defineutils from the Command-line

When you run a module with the -m switch it will execute the defineutils modules from the command-line. For example, to transform a define.xml file into HTML using the stylesheet, the following command-line example executes the module to generate define.html. The -m parameter instructs Python to run the module as an application. The definehtml program uses the -d parameter to specify the define.xml file path and the -o to specify the define.html file path.

python3 -m defineutils.definehtml -d tests/define.xml -o tests/define.html

The validate command can be executed using the command-line the same way. For validate, only the -d parameter is required to indicate the file path of the define.xml to validate.

python3 -m defineutils.validate -d tests/define.xml

If you are running defineutils from the source code using a virtual environment, you may need to activate that virtual environment before running the code from the command-line.

source .venv/bin/activate
python3 -m defineutils.validate -d tests/define.xml

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

defineutils-0.2.0.tar.gz (60.2 kB view details)

Uploaded Source

Built Distribution

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

defineutils-0.2.0-py3-none-any.whl (66.4 kB view details)

Uploaded Python 3

File details

Details for the file defineutils-0.2.0.tar.gz.

File metadata

  • Download URL: defineutils-0.2.0.tar.gz
  • Upload date:
  • Size: 60.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for defineutils-0.2.0.tar.gz
Algorithm Hash digest
SHA256 378eb914d7211c201c76206d0389caf17bb31ad693681b60357b8b603abf0d8c
MD5 fec115bc6744beb4b14018eb95e4e1c6
BLAKE2b-256 39453592b7d044cd86b5d528da94c16931d0c54913751edef4cadd5fecaca83a

See more details on using hashes here.

File details

Details for the file defineutils-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: defineutils-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 66.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for defineutils-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 061b94a0fada9970b06be34b9c49a0f766c56a237e8e51d891ca07a65186c015
MD5 58de6641b065c6423d1082d416ccc43d
BLAKE2b-256 60deb5a871e4ae6710d00f2bd1f3a99012ccfda7a595854e878ba4499855747e

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