<p>No sane application should EVER attempt to validate a private key by attempting to pass it to an external API. That's a ridiculously easy way to lose all your funds if the API operator is malicious, compromised, or someone is eavesdropping on your communication with said API.</p>
<p>You should do this yourself, preferably using a well tested, community supported, open source library for your choice of language - most major languages have such libraries.</p>
<p>If this is too much work, you should reconsider building something like this. Do not compromise on safety, especially if you intend for other people to trust this code with their funds.</p>

CC BY-SA 4.0
2020-08-02T08:21:12.783Z
I now see that I did not explained myself correctly. I meant that I need a library and not API (a code that I can download from github or somewhere else and use it in my code without copyrights issues). I will edit my question accordingly. thank you @Raghav Sood
Avi El
CC BY-SA 4.0
2020-07-31T13:26:40.550Z
2020-07-31T13:26:40.550Z
Raghav Sood
<p>See if this library will suit you
<a href="https://github.com/bitaps-com/pybtc" rel="nofollow noreferrer">https://github.com/bitaps-com/pybtc</a></p>

CC BY-SA 4.0
2020-08-03T17:19:59.663Z
2020-08-03T17:19:59.663Z
bitaps.com
<p>I am building a python script that gets a string and determines if it is a valid bitcoin private key or public key, and if so it returns its type/format (base58, BIP32, HexaDecimal etc.) and its derivations (public key from private key and address from public key).</p>
<p>Is there any <strong>free</strong> library that I can use its code inside mine, to get those details?</p>
<p>I have tried to do so myself but there are a lot of formats of keys and mathematical computations for validation and derivation the keys.
Thank you.</p>

<private-key><api><public-key><python><validation>
library for validating bitcoin private and public keys
Avi El
# library for validating bitcoin private and public keys

(Asked by: username_0 on 2020-07-31)

I am building a python script that gets a string and determines if it is a valid bitcoin private key or public key, and if so it returns its type/format (base58, BIP32, HexaDecimal etc.) and its derivations (public key from private key and address from public key).

Is there any **free** library that I can use its code inside mine, to get those details?

I have tried to do so myself but there are a lot of formats of keys and mathematical computations for validation and derivation the keys.
Thank you.

**Tags:** private-key, api, public-key, python, validation


---

## 2 answers

### Answer by username_1 on 2020-07-31. Score: 2

No sane application should EVER attempt to validate a private key by attempting to pass it to an external API. That's a ridiculously easy way to lose all your funds if the API operator is malicious, compromised, or someone is eavesdropping on your communication with said API.

You should do this yourself, preferably using a well tested, community supported, open source library for your choice of language - most major languages have such libraries.

If this is too much work, you should reconsider building something like this. Do not compromise on safety, especially if you intend for other people to trust this code with their funds.

> **Comments:**
> **username_0**: I now see that I did not explained myself correctly. I meant that I need a library and not API (a code that I can download from github or somewhere else and use it in my code without copyrights issues). I will edit my question accordingly. thank you @username_1  

---

### Answer by username_2 on 2020-08-03. Score: 0

See if this library will suit you
<https://github.com/username_2/pybtc>


---

