prance.util.formats

This submodule contains file format related utility code for Prance.

Exceptions

exception prance.util.formats.ParseError[source]

Bases: exceptions.ValueError

Functions

prance.util.formats.parse_spec(spec_str, filename=None, **kwargs)[source]

Return a parsed dict of the given spec string.

The default format is assumed to be JSON, but if you provide a filename, its extension is used to determine whether YAML or JSON should be parsed.

Parameters:
  • spec_str (str) – The specifications as string.
  • filename (str) – [optional] Filename to determine the format from.
  • content_type (str) – [optional] Content type to determine the format from.
Returns:

The specifications.

Return type:

dict

prance.util.formats.serialize_spec(specs, filename=None, **kwargs)[source]

Return a serialized version of the given spec.

The default format is assumed to be JSON, but if you provide a filename, its extension is used to determine whether YAML or JSON should be parsed.

Parameters:
  • specs (str) – The specifications as dict.
  • filename (str) – [optional] Filename to determine the format from.
  • content_type (str) – [optional] Content type to determine the format from.
Returns:

The serialized specifications.

Return type:

str