It depends on what precisely you mean when you say that a python variable is a jpeg image. Do you mean that it's a string containing the contents of a jpeg image file? So if you wrote it to disk you'd get a jpeg image file?
If that's what you mean, you can do it with PIL and StringIO. (There might be an easier way.)
import pygame
from PIL import Image
from cStringIO import StringIO
# create an example pygame image
img = pygame.Surface((100, 100))
pygame.draw.circle(img, (255, 0, 0), (50, 50), 40)
# convert to PIL format
imgstr = pygame.image.tostring(img, "RGB", False)
pimg = Image.fromstring("RGB", img.get_size(), imgstr)
# save to string
s = StringIO()
pimg.save(s, "JPEG")
r = s.getvalue()
s.close()
# r is a string with the contents of a jpeg file. to confirm:
open("img.jpg", "wb").write(r)
However, this doesn't seem like a very useful thing to have (and if I needed it so badly I would just write it to disk and read it back) so I may be misunderstanding you.