code: def pdf_rotate(
      input: str,
      counter_clockwise: bool = False,
      pages: [str] = None,
      output: str = None,
  ):
      
      infile = open(input, "rb")
      reader = PdfFileReader(infile)
      writer = PdfFileWriter()
  
      # get pages from source depending on pages parameter
      if pages is None:
          source_pages = reader.pages
      else:
          pages = parse_rangearg(pages, len(reader.pages))
          source_pages = [reader.getPage(i) for i in pages]
  
      # rotate pages and add to writer
      for i, page in enumerate(source_pages):
          if pages is None or i in pages:
              if counter_clockwise:
                  writer.addPage(page.rotateCounterClockwise(90))
              else:
                  writer.addPage(page.rotateClockwise(90))
          else:
              writer.addPage(page)
  
      # Open output file or temporary file for writing
      if output is None:
          outfile = NamedTemporaryFile(delete=False)
      else:
          if not os.path.isfile(output) or overwrite_dlg(output):
              outfile = open(output, "wb")
          else:
              return
  
      # Write to file
      writer.write(outfile)
      infile.close()
      outfile.close()
  
      # If no output defined move temporary file to input
      if output is None:
          if overwrite_dlg(input):
              os.remove(input)
              move(outfile.name, input)
          else:
              os.remove(outfile.name)
docs: Rotate the given Pdf files clockwise or counter clockwise.
      :param inputs: pdf files
      :param counter_clockwise: rotate counter clockwise if true else clockwise
      :param pages: list of page numbers to rotate, if None all pages will be
          rotated