clearbit / clearbit-python Goto Github PK
View Code? Open in Web Editor NEWClearbit Python library
Home Page: https://clearbit.com/docs
License: MIT License
Clearbit Python library
Home Page: https://clearbit.com/docs
License: MIT License
I was just looking over this code, and if I'm not mistaken, Person.flag
should do something with attrs
:
https://github.com/clearbit/clearbit-python/blob/master/clearbit/enrichment/person.py#L19
Also, this probably doesn't make a huge difference, but I would think that it would be considered more pythonic to do self.post(...)
instead of self.__class__.post(...)
.
I am doing this code:
`
people = clearbit.Prospector.search(domain="twitter.com", role='marketing')
if people:
for person in people:
print(person)`
But I am getting this result on the print.
page page_size total results
Hi!
Just a quick note that the docs state that the Enrichment
API will except additional parameters in an effort to improve the match rate however the python library does not accept those parameters. Is there a plan to support additional keywords at some point?
When attempting to hit clearbit.Enrichment.find()
and passing the email_address
and ip_address
I receive clearbit.error.ParamsInvalidError: Invalid values
Docs I was referencing are here: https://clearbit.com/docs?python#enrichment-api
After setuptools 58.* was released in the last few days disallowing the parameter use_2to3 (in setup.py), clearbit fails to install.
$ pip install clearbit
Collecting clearbit Downloading clearbit-0.1.7.tar.gz (5.0 kB)
ERROR: Command errored out with exit status 1:
command: /var/virtualenv/py37/bin/python -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-1neb7o7s/clearbit_9b2
c9bb86a3047dabc1f8b18e18ae25a/setup.py'"'"'; __file__='"'"'/tmp/pip-install-1neb7o7s/clearbit_9b2c9bb86a3047dabc1f8b18e18ae25a/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-8vb5blw9 cwd: /tmp/pip-install-1neb7o7s/clearbit_9b2c9bb86a3047dabc1f8b18e18ae25a/
Complete output (1 lines):
error in clearbit setup command: use_2to3 is invalid.
----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/50/e7/bbd7c4525cb4ecb74fbe7f4dff6f4112342d9050d64b3be8d56b8c0a028b/clearbit-0.1.7.tar.gz#sha256=f1
d5b854a9b0e8d6644bad2594f9e65ab756ffb0c6c34db15ecfc1e9179bb883 (from https://pypi.org/simple/clearbit/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
I am trying to pip install clearbit per the following guidance: Link 1 Link 2
I am on Python 3.9.7 and pip version 21.3. I have also updated my setuptools per other stackoverflow answers.
The command I am running on my Mac Terminal is:
pip install clearbit
But I am met with a series of errors. An example error block states:
Using cached clearbit-0.0.2.tar.gz (2.9 kB)
Preparing metadata (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: /Library/Frameworks/Python.framework/Versions/3.9/bin/python3 -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/nv/d5h78rrs0t9625k940k5f4ww0000gn/T/pip-install-plp1xoqf/clearbit_e710a979acd3433290a538760255e4c4/setup.py'"'"'; __file__='"'"'/private/var/folders/nv/d5h78rrs0t9625k940k5f4ww0000gn/T/pip-install-plp1xoqf/clearbit_e710a979acd3433290a538760255e4c4/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/nv/d5h78rrs0t9625k940k5f4ww0000gn/T/pip-pip-egg-info-jnpe31nd
cwd: /private/var/folders/nv/d5h78rrs0t9625k940k5f4ww0000gn/T/pip-install-plp1xoqf/clearbit_e710a979acd3433290a538760255e4c4/
Complete output (1 lines):
error in clearbit setup command: use_2to3 is invalid.
----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/71/44/d8de83ca49c310895481e2f9d4657476c323a60b3186be7afeb584814263/clearbit-0.0.2.tar.gz#sha256=b39180db8e6ac159febe54fb0e0e84c8f0c8facf832c551c1175c758c255326b (from https://pypi.org/simple/clearbit/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
Using cached clearbit-0.0.1.tar.gz (2.7 kB)
Preparing metadata (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: /Library/Frameworks/Python.framework/Versions/3.9/bin/python3 -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/nv/d5h78rrs0t9625k940k5f4ww0000gn/T/pip-install-plp1xoqf/clearbit_4716e56973294efd87482725d29438ec/setup.py'"'"'; __file__='"'"'/private/var/folders/nv/d5h78rrs0t9625k940k5f4ww0000gn/T/pip-install-plp1xoqf/clearbit_4716e56973294efd87482725d29438ec/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/nv/d5h78rrs0t9625k940k5f4ww0000gn/T/pip-pip-egg-info-3_q7g_32
cwd: /private/var/folders/nv/d5h78rrs0t9625k940k5f4ww0000gn/T/pip-install-plp1xoqf/clearbit_4716e56973294efd87482725d29438ec/
Complete output (5 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/nv/d5h78rrs0t9625k940k5f4ww0000gn/T/pip-install-plp1xoqf/clearbit_4716e56973294efd87482725d29438ec/setup.py", line 22, in <module>
with open('README.md') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'README.md'
----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/0d/50/76018c4fd50de45bd927010ae85c7c0e2f8f385f3e90e1ca6aedc5a2ded6/clearbit-0.0.1.tar.gz#sha256=247b48b17c9052aac5551bd6fa1da617f50a8ba883ab78827df53228ead0da57 (from https://pypi.org/simple/clearbit/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ERROR: Could not find a version that satisfies the requirement clearbit (from versions: 0.0.1, 0.0.2, 0.0.4, 0.0.5, 0.0.6, 0.0.7, 0.0.8, 0.1.0, 0.1.1, 0.1.2, 0.1.3, 0.1.4, 0.1.5, 0.1.6, 0.1.7)
ERROR: No matching distribution found for clearbit
I can't find any guidance on how to troubleshoot this issue. I wondered if anyone has any ideas on how to troubleshoot this? I'm quite new to Python and CLI so any help would be appreciated!
#10 should fix this.
When turning the response into a dict. Ie dict(response). I get that error.
clearbit-python/clearbit/resource.py
Line 46 in 5594e82
The use of "requests" component library on a multi-thread context with a large number of concurrent threads requests data to Clearbit Servers, as an example, using the Reveal API to find company data by IP. We could got an error from server. But, this is not an issue on server side, because server has a limit and this is fine. The problem is how to handle this issue on client side.
So, I made an improve on my own using the code below:
A little brief on this code: Find company by IP.
To highlight the improvement, the code add a Retry strategy to handle issues when the server returns the status code [429, 500, 502, 503, 504. Just remembering that this is from my case, we should refactor this using a factory + configuration design model to avoid hardocoded configuration on this end.
@staticmethod
def __createSession__():
session = requests.Session()
retry = Retry(
total=3,
backoff_factor=1,
status_forcelist=[429, 500, 502, 503, 504],
method_whitelist=["HEAD", "GET", "OPTIONS"]
)
adapter = HTTPAdapter(max_retries=retry)
session.mount('http://', adapter)
session.mount('https://', adapter)
return session
def findCompanyInfoByIp(self, ip: string) -> ClearbitResult:
if ip is None or ip == "":
return ErrorClearbitResult(f"Can't find clearbit data with a valid ip")
url = f"{BASE_URL}/find?ip={urllib.parse.quote(ip)}"
try:
response = \
self.__requestSession.get(
url,
auth=BearerAuth(self.__authToken))
return ClearbitResult(response)
except Exception as e:
errorMessage = f"Error requesting Clearbit at [{url}]: {e}"
self.__logger.error(errorMessage)
return ErrorClearbitResult(errorMessage)
This solution helps me to ensure 100 or maybe more threands to requests Clearbit Reveal API using a simple retry strategy.
Could this be an improvement to help this library?
Hi, I am using clearbit module to get the company information from the domain name. I tried to handle HTTPException, but somehow it is not recognized and throwing one more Exception NameError. Please find the code below.
import clearbit
def abc(i):
try:
company = clearbit.Company.find(domain=i,stream=True)
if company['name'] is None:
return "No customer"
else: return company['name']
except HTTPError as e:
s="No customer"
return s
abc('244treqda.com')
Can you please look into this issue and help me how to handle this HTTP exception
HTTPError Traceback (most recent call last)
in abc(i)
3 try:
----> 4 company = clearbit.Company.find(domain=i,stream=True)
5 if company['name'] is None:
~\AppData\Local\Continuum\anaconda3\lib\site-packages\clearbit\enrichment\company.py in find(cls, **options)
15
---> 16 return cls.get(url, **options)
17
~\AppData\Local\Continuum\anaconda3\lib\site-packages\clearbit\resource.py in get(cls, url, **values)
54 else:
---> 55 response.raise_for_status()
56
~\AppData\Local\Continuum\anaconda3\lib\site-packages\requests\models.py in raise_for_status(self)
939 if http_error_msg:
--> 940 raise HTTPError(http_error_msg, response=self)
941
HTTPError: 422 Client Error: Unprocessable Entity for url: https://company-stream.clearbit.com/v2/companies/find?domain=244treqda.com
During handling of the above exception, another exception occurred:
NameError Traceback (most recent call last)
in
----> 1 abc('244treqda.com')
in abc(i)
7 else:
8 return company['name']
----> 9 except HTTPError as e:
10 s="No customer"
11 return s
NameError: name 'HTTPError' is not defined
In [119]:
try:
clearbit.Company.find(domain=i,stream=True)
except urllib2.HTTPError as err:
if err.code == 422:
return "No customer"
I tried running the example from the docs (and other queries as well to this endpoint)
clearbit.Discovery.search(
query={'tech': 'marketo', 'raised': '100000~'},
sort='alexa_asc'
)
and i get an error from requests library saying: TypeError: request() got an unexpected keyword argument 'json'
clearbit package requirements are requests >= 0.8.8 and I am using requests==1.0.4 but the json parameter was added to requests in version 2.4.2. Upgrading the requirement version number would not be the right solution, I may suggest using the 'data' kwarg instead and encode the payload. But as a side note as well I noticed that this is making a POST while the docs have it as a GET...
When I tried to test this out though I still could not get a valid response but I may be doing something incorrect (same result when get is a post too)
endpoint = 'https://discovery.clearbit.com/v1/companies/search'
>>> resp = requests.get(endpoint, auth=(<key>, ''),
data=json.dumps({"query": {"raised": "100000~", "tech": "marketo"}})
)
>>> resp.json()
{u'error': {u'message': u'"query" param is required. Check https://clearbit.com/docs.',
u'type': u'validation'}}
This error that requests is throwing will happen for any of the other APIs that are using POST as well with an older requests version, but this was the first one I tested
The docs say your client libraries will handle signature verification:
https://clearbit.com/docs#webhooks-securing-webhooks
but I see no evidence of this in the python library.
Looking for a usage example for using python to pull domain from a company name.
Since it's not guaranteed that some data presents it seems reasonable to check replies with dict.get method company.get('some_data', 'default').
However it's not possible, because get method is overlapped.
There is exist a workaround: company = dict(company).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.