svglib API Reference

Pure-Python library for reading SVG files and converting them to ReportLab Drawing objects.

svglib.Optional
Python Library Documentation: _SpecialForm in module typing

Optional = typing.Optional
    Optional[X] is equivalent to Union[X, None].
svglib.PackageNotFoundError
Python Library Documentation: class PackageNotFoundError in module importlib.metadata

class PackageNotFoundError(builtins.ModuleNotFoundError)
 |  The package was not found.
 |
 |  Method resolution order:
 |      PackageNotFoundError
 |      builtins.ModuleNotFoundError
 |      builtins.ImportError
 |      builtins.Exception
 |      builtins.BaseException
 |      builtins.object
 |
 |  Methods defined here:
 |
 |  __str__(self)
 |      Return str(self).
 |
 |  ----------------------------------------------------------------------
 |  Readonly properties defined here:
 |
 |  name
 |      module name
 |
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |
 |  __weakref__
 |      list of weak references to the object
 |
 |  ----------------------------------------------------------------------
 |  Methods inherited from builtins.ModuleNotFoundError:
 |
 |  __init__(self, /, *args, **kwargs)
 |      Initialize self.  See help(type(self)) for accurate signature.
 |
 |  ----------------------------------------------------------------------
 |  Methods inherited from builtins.ImportError:
 |
 |  __reduce__(...)
 |      Helper for pickle.
 |
 |  ----------------------------------------------------------------------
 |  Data descriptors inherited from builtins.ImportError:
 |
 |  msg
 |      exception message
 |
 |  name_from
 |      name imported from module
 |
 |  path
 |      module path
 |
 |  ----------------------------------------------------------------------
 |  Static methods inherited from builtins.Exception:
 |
 |  __new__(*args, **kwargs) class method of builtins.Exception
 |      Create and return a new object.  See help(type) for accurate signature.
 |
 |  ----------------------------------------------------------------------
 |  Methods inherited from builtins.BaseException:
 |
 |  __getattribute__(self, name, /)
 |      Return getattr(self, name).
 |
 |  __repr__(self, /)
 |      Return repr(self).
 |
 |  __setstate__(...)
 |
 |  add_note(...)
 |      Exception.add_note(note) --
 |      add a note to the exception
 |
 |  with_traceback(...)
 |      Exception.with_traceback(tb) --
 |      set self.__traceback__ to tb and return self.
 |
 |  ----------------------------------------------------------------------
 |  Data descriptors inherited from builtins.BaseException:
 |
 |  __cause__
 |      exception cause
 |
 |  __context__
 |      exception context
 |
 |  __dict__
 |
 |  __suppress_context__
 |
 |  __traceback__
 |
 |  args
svglib.basename
Python Library Documentation: function basename in module ntpath

basename(p)
    Returns the final component of a pathname
svglib.datetime
Python Library Documentation: class datetime in module datetime

class datetime(date)
 |  datetime(year, month, day[, hour[, minute[, second[, microsecond[,tzinfo]]]]])
 |
 |  The year, month and day arguments are required. tzinfo may be None, or an
 |  instance of a tzinfo subclass. The remaining arguments may be ints.
 |
 |  Method resolution order:
 |      datetime
 |      date
 |      builtins.object
 |
 |  Methods defined here:
 |
 |  __add__(self, value, /)
 |      Return self+value.
 |
 |  __eq__(self, value, /)
 |      Return self==value.
 |
 |  __ge__(self, value, /)
 |      Return self>=value.
 |
 |  __getattribute__(self, name, /)
 |      Return getattr(self, name).
 |
 |  __gt__(self, value, /)
 |      Return self>value.
 |
 |  __hash__(self, /)
 |      Return hash(self).
 |
 |  __le__(self, value, /)
 |      Return self<=value.
 |
 |  __lt__(self, value, /)
 |      Return self<value.
 |
 |  __ne__(self, value, /)
 |      Return self!=value.
 |
 |  __radd__(self, value, /)
 |      Return value+self.
 |
 |  __reduce__(...)
 |      __reduce__() -> (cls, state)
 |
 |  __reduce_ex__(...)
 |      __reduce_ex__(proto) -> (cls, state)
 |
 |  __repr__(self, /)
 |      Return repr(self).
 |
 |  __rsub__(self, value, /)
 |      Return value-self.
 |
 |  __str__(self, /)
 |      Return str(self).
 |
 |  __sub__(self, value, /)
 |      Return self-value.
 |
 |  astimezone(...)
 |      tz -> convert to local time in new timezone tz
 |
 |  ctime(...)
 |      Return ctime() style string.
 |
 |  date(...)
 |      Return date object with same year, month and day.
 |
 |  dst(...)
 |      Return self.tzinfo.dst(self).
 |
 |  isoformat(...)
 |      [sep] -> string in ISO 8601 format, YYYY-MM-DDT[HH[:MM[:SS[.mmm[uuu]]]]][+HH:MM].
 |      sep is used to separate the year from the time, and defaults to 'T'.
 |      The optional argument timespec specifies the number of additional terms
 |      of the time to include. Valid options are 'auto', 'hours', 'minutes',
 |      'seconds', 'milliseconds' and 'microseconds'.
 |
 |  replace(...)
 |      Return datetime with new specified fields.
 |
 |  time(...)
 |      Return time object with same time but with tzinfo=None.
 |
 |  timestamp(...)
 |      Return POSIX timestamp as float.
 |
 |  timetuple(...)
 |      Return time tuple, compatible with time.localtime().
 |
 |  timetz(...)
 |      Return time object with same time and tzinfo.
 |
 |  tzname(...)
 |      Return self.tzinfo.tzname(self).
 |
 |  utcoffset(...)
 |      Return self.tzinfo.utcoffset(self).
 |
 |  utctimetuple(...)
 |      Return UTC time tuple, compatible with time.localtime().
 |
 |  ----------------------------------------------------------------------
 |  Class methods defined here:
 |
 |  combine(...)
 |      date, time -> datetime with same date and time fields
 |
 |  fromisoformat(...)
 |      string -> datetime from a string in most ISO 8601 formats
 |
 |  fromtimestamp(...)
 |      timestamp[, tz] -> tz's local time from POSIX timestamp.
 |
 |  now(tz=None)
 |      Returns new datetime object representing current time local to tz.
 |
 |        tz
 |          Timezone object.
 |
 |      If no tz is specified, uses local timezone.
 |
 |  strptime(...)
 |      string, format -> new datetime parsed from a string (like time.strptime()).
 |
 |  utcfromtimestamp(...)
 |      Construct a naive UTC datetime from a POSIX timestamp.
 |
 |  utcnow(...)
 |      Return a new datetime representing UTC day and time.
 |
 |  ----------------------------------------------------------------------
 |  Static methods defined here:
 |
 |  __new__(*args, **kwargs)
 |      Create and return a new object.  See help(type) for accurate signature.
 |
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |
 |  fold
 |
 |  hour
 |
 |  microsecond
 |
 |  minute
 |
 |  second
 |
 |  tzinfo
 |
 |  ----------------------------------------------------------------------
 |  Data and other attributes defined here:
 |
 |  max = datetime.datetime(9999, 12, 31, 23, 59, 59, 999999)
 |
 |  min = datetime.datetime(1, 1, 1, 0, 0)
 |
 |  resolution = datetime.timedelta(microseconds=1)
 |
 |  ----------------------------------------------------------------------
 |  Methods inherited from date:
 |
 |  __format__(...)
 |      Formats self with strftime.
 |
 |  isocalendar(...)
 |      Return a named tuple containing ISO year, week number, and weekday.
 |
 |  isoweekday(...)
 |      Return the day of the week represented by the date.
 |      Monday == 1 ... Sunday == 7
 |
 |  strftime(...)
 |      format -> strftime() style string.
 |
 |  toordinal(...)
 |      Return proleptic Gregorian ordinal.  January 1 of year 1 is day 1.
 |
 |  weekday(...)
 |      Return the day of the week represented by the date.
 |      Monday == 0 ... Sunday == 6
 |
 |  ----------------------------------------------------------------------
 |  Class methods inherited from date:
 |
 |  fromisocalendar(...)
 |      int, int, int -> Construct a date from the ISO year, week number and weekday.
 |
 |      This is the inverse of the date.isocalendar() function
 |
 |  fromordinal(...)
 |      int -> date corresponding to a proleptic Gregorian ordinal.
 |
 |  today(...)
 |      Current date or datetime:  same as self.__class__.fromtimestamp(time.time()).
 |
 |  ----------------------------------------------------------------------
 |  Data descriptors inherited from date:
 |
 |  day
 |
 |  month
 |
 |  year
svglib.dirname
Python Library Documentation: function dirname in module ntpath

dirname(p)
    Returns the directory component of a pathname
svglib.exists
Python Library Documentation: built-in function _path_exists in module nt

_path_exists(path, /)
    Test whether a path exists.  Returns False for broken symbolic links.
svglib.main
Python Library Documentation: function main in module svglib

main() -> None
    Main entry point for the CLI.
svglib.splitext
Python Library Documentation: function splitext in module ntpath

splitext(p)
    Split the extension from a pathname.

    Extension is everything from the last dot to the end, ignoring
    leading dots.  Returns "(root, ext)"; ext may be empty.
svglib.svg2pdf
Python Library Documentation: function svg2pdf in module svglib

svg2pdf(path: str, outputPat: Optional[str] = None) -> None
    Convert an SVG file to PDF format.

    High-level function that loads an SVG file, converts it to a ReportLab drawing,
    and saves it as a PDF file. Supports both .svg and .svgz (compressed SVG) files.

    Args:
        path: Path to the input SVG file (.svg or .svgz extension).
        outputPat: Optional output path pattern. Supports placeholders:
            - %(dirname)s: Directory of input file
            - %(basename)s: Full filename with extension
            - %(base)s: Filename without extension
            - %(ext)s: File extension
            - %(now)s: Current datetime object
            - %(format)s: Output format (always "pdf")
            Also supports {name} format strings.

    Returns:
        None. The PDF file is written to disk.

    Raises:
        FileNotFoundError: If the input SVG file does not exist.
        Exception: If SVG parsing or PDF generation fails.
        OSError: If the output directory is not writable.

    Examples:
        Basic conversion:
        >>> svg2pdf("input.svg")  # Creates "input.pdf"

        Custom output location:
        >>> svg2pdf("input.svg", "output.pdf")

        Using placeholders:
        >>> svg2pdf("path/file.svg", "%(dirname)s/converted/%(base)s.pdf")
        # Creates "path/converted/file.pdf"

        Timestamped output:
        >>> svg2pdf("file.svg", "backup/%(now.year)s-%(now.month)s-%(base)s.pdf")

    Note:
        The function will overwrite existing PDF files without warning.
        For compressed SVG files (.svgz), the file is automatically decompressed.
svglib.version
Python Library Documentation: function version in module importlib.metadata

version(distribution_name)
    Get the version string for the named package.

    :param distribution_name: The name of the distribution package to query.
    :return: The version string for the package as defined in the package's
        "Version" metadata key.