Python Barcode Generator
The code generally looks pretty good, but I think there are some things you could fix up here.

Don't forget the stop code

You have the start code of 0000 but you've forgotten the stop code which is 100.  When you calculate, you could just tack it onto the end with bits += '100' 

Use SVG &lt;def&gt;s

Since the purpose is to create an SVG barcode, it make sense to tighten the resulting SVG.  You may already know how to use a &lt;def&gt; in SVG and it definitely makes things a little easier to understand here.  The way your code is currently structures, it creates four different styles of &lt;rect&gt; which are all combinations of narrow/wide and black/white.  You could predefine each of those shapes and then simply intantiate them within the body of the svg code.  That would make the definition for svg and bar like this:

svg = '''&lt;svg height="50"&gt;&lt;defs&gt;
&lt;g id="b0"&gt;&lt;rect x="0" y="0" width="2" height="50"/&gt;&lt;/g&gt;
&lt;g id="b1"&gt;&lt;rect x="0" y="0" width="4" height="50"/&gt;&lt;/g&gt;
&lt;/defs&gt;'''
bar = '&lt;use xlink:href="#b{0}" x="{1}" y="0" {2}/&gt;'


Using it would then be 

svg += bar.format(bit, pos, style)


An improvement would be to create both bars and spaces like this:

&lt;g id="b0"&gt;&lt;rect x="0" y="0" width="2" height="50" style="fill:rgb(0,0,0)"/&gt;&lt;/g&gt;
&lt;g id="b1"&gt;&lt;rect x="0" y="0" width="4" height="50" style="fill:rgb(0,0,0)"/&gt;&lt;/g&gt;
&lt;g id="s0"&gt;&lt;rect x="0" y="0" width="2" height="50" style="fill:rgb(255,255,255)"/&gt;&lt;/g&gt;
&lt;g id="s1"&gt;&lt;rect x="0" y="0" width="4" height="50" style="fill:rgb(255,255,255)"/&gt;&lt;/g&gt;


Then your loop could look then like this:

for i, bit in enumerate(bits):
    width = int(bit) * 2 + 2
    svg += bar.format('bs'[i%2], bit, pos)
    pos += width


Although that may look verbose, it actually is over 2k shorter for a 12 digit barcode.

Think carefully about data representation

Your code currently translates digits into a series of '1' and '0' characters and then translates again into SVG rectangles.  Why not eliminate a step? Your code could just as easily translate them in a single operation.

Use list comprehensions instead of for loops

The use of list comprehensions is almost always faster than a for loop in Python, so we use them when we can.  It also tends to make the code shorter.  So for example, we could change your loop to calculate the string of bar code bits to calculate all the black bits and then all the white bits like this:

black = "".join([bytes[i] for i in digits[0::2]])
white = "".join([bytes[i] for i in digits[1::2]])
# shuffle them together
databits = "".join("".join(i) for i in zip(black,white))
# create the full bar code string with start and stop
bits = "".join(['0000',databits,'100'])


Doing this with join also saves time.  Appending strings with += is very slow in Python.

Prefer xrange to range

When you use range, a whole list object is created, using memory.  With xrange, a generator is created instead populated which can save memory.  For any reasonably sized bar code this won't make much difference here, but it's good practice for Python 2.7.  In Python 3, xrange doesn't exist and range creates a generator, so keep that in mind if you change versions.

Don't draw more than you have to

You're drawing one &lt;rect&gt; for every bar or space, but it's really not necessary.  Instead, you could create one larger rectangle that's the "background" space color and then only draw the black bars.