If you've locked yourself out of your house and this time and you didn't prepare for this possibility, then you'll probably just have to call a locksmith. However, you can take this opportunity to prepare better for this happening in the future. There are tech methods out there these days that are both secure and resistant to accidental lockouts.
Store Your Key Pattern Digitally
There are a number of key services out there these days that let you scan your key and then save the pattern. Then, if you ever lock yourself out of your house, you can simply go to a local kiosk for the key and have a copy made right then using the stored pattern. It helps to look for a kiosk that's in the lobby area at the front of a store before the front door and make note of it.
That way, even if you realize that you've been locked out of your house at 2 in the morning, you can head down to a kiosk and you'll still have access to it even if the store itself is closed. The kiosk will print out your key while you wait, using info that you've stored on it previously. Many of these companies can share information between kiosks so you have a lot of flexibility on which one you can use too.
Smartphone Controlled Locks
If you lock your key in your house by accident, one approach is just to have another means of getting past the lock that doesn't break it. There are smartphone-controlled locks you can get now that give you this capability. The lock will still work with a key, but you can also add other means of making it unlock.
Some of these locks make it so that you can authorize a smartphone to open it. This is still secure, however, since you can usually go to their online page with your screen name to authorize or unauthorized a phone at any time. That way, if someone steals your phone, you can make it impossible for them to open your door. In this way, this is even better than a key.
It also makes it so that you can use your phone to open your door if you misplace your key. If you misplace your phone, as long as you have access to another computer, you can authorize a different phone even.
Overall, you'll sleep better if you have options for potential lockouts ahead of time. This way you can prevent a lockout from happening again after you deal with the current one.