It's not common to change key signature in the middle of a bar - my edition of Behind Bars says "change a key signature after a barline", with no qualifications, suggesting that's the usual way to do things.
But, nevertheless, changing the key signature mid-bar is still seen occasionally: for example in Beethoven, Piano Sonata 31:

(which also has a nice example of changing time signature between barlines, as well).
There are also other examples - from Beethoven, in the introduction to the fugue of the Hammerklavier, there are three more key changes between barlines, two of which can be seen below:

and in the final movement of Sonata 9:

plus a few clearly metrical examples from other composers - Ravel, Le Tombeau de Couperin:

and one from Busoni, Piano Concerto Op.39 (but there are at least five in that work):

Whether that's the best way to notate your music is a different question, I guess - but I think it's valid, if that's the way you want to go.
Note that according to traditional practice, the old key signature should be explicitly cancelled with natural signs before the new one is written. From my edition of Behind Bars, page 92:
Natural signs cancel a key signature before a new one is stated. The naturals should appear in the order of the key signature they are cancelling.
The following page states that in contemporary practice it's okay to just write the new key signature without cancelling the old one with naturals (unless the new key signature is 'no key signature'). In a search through a bunch of my piano music, it seems like both styles are used.