Skip to content

FahadNoor/py_crunchbase

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyCrunchbase

Tests codecov License: MIT PyPI pyversions

PyCrunchbase is a python client for Crunchbase's REST API. Crunchbase provides 4 types of APIs:-

  1. Search API
  2. Autocomplete API
  3. Deleted Entities API
  4. Entities API

PyCrunchbase supports all of these through a very simple interface.

Installation

Use the package manager pip to install PyCrunchbase.

pip install py-crunchbase-api

Usage

from py_crunchbase import PyCrunchbase

# API key can be set as the env variable PY_CRUNCHBASE_API_KEY 
pycb = PyCrunchbase()

# OR passed as an argument
pycb = PyCrunchbase('api_key')

# If both are provided, the latter will take preference

Search API

from py_crunchbase import PyCrunchbase
from py_crunchbase.apis.search.predicates import Currency

pycb = PyCrunchbase()
api = pycb.search_funding_rounds_api()

api.select(
    'identifier', 'announced_on', 'funded_organization_identifier', 'money_raised', 'investment_type'
).where(
    announced_on__gte=2012, num_investors__lte=4, money_raised__gte=Currency(10000000)
).order_by(
    'announced_on'
)

for page in api.iterate():
    for funding_round in page:
        print(funding_round.permalink)
from py_crunchbase import PyCrunchbase, Entities
from py_crunchbase.apis.search.predicates import Currency

pycb = PyCrunchbase()
api = pycb.search_organizations_api()

org_facet_ids = Entities.Organization.Facets
api.select(
    'identifier', 'categories', 'location_identifiers', 'short_description', 'rank_org'
).where(
    funding_total__between=[Currency(25000000), Currency(100000000)],
    location_identifiers__includes=['6106f5dc-823e-5da8-40d7-51612c0b2c4e'],
    facet_ids__includes=[org_facet_ids.company]
).order_by(
    'rank_org'
)

for page in api.iterate():
    for company in page:
        print(company.permalink)
from py_crunchbase import PyCrunchbase

pycb = PyCrunchbase()
api = pycb.search_organizations_api()

api.select(
    'identifier', 'categories', 'location_identifiers', 'short_description', 'rank_org'
).where(
    num_employees_enum__includes=['c_00101_00250'],
    categories__includes=['58842728-7ab9-5bd1-bb67-e8e55f6520a0']
).order_by(
    'rank_org'
)

for page in api.iterate():
    for company in page:
        print(company.permalink)

Autocomplete API

from py_crunchbase import PyCrunchbase

pycb = PyCrunchbase()
api = pycb.autocomplete_api()

for entity in api.autocomplete('box').limit(15).execute():
    print(entity.permalink, entity.uuid)
from py_crunchbase import PyCrunchbase, Collections

pycb = PyCrunchbase()
api = pycb.autocomplete_api()

for entity in api.autocomplete('mayfield').select_collections(Collections.Principals.investors).execute():
    print(entity.permalink, entity.uuid)
from py_crunchbase import PyCrunchbase, Collections

pycb = PyCrunchbase()
api = pycb.autocomplete_api()

for entity in api.autocomplete('mobile payment').select_collections(
        Collections.Categories, Collections.CategoryGroups
).limit(10).execute():
    print(entity.permalink, entity.uuid)
from py_crunchbase import PyCrunchbase, Collections

pycb = PyCrunchbase()
api = pycb.autocomplete_api()

for entity in api.autocomplete('airbnb').select_collections(Collections.Organizations.companies).execute():
    print(entity.permalink, entity.uuid)
from py_crunchbase import PyCrunchbase, Collections

pycb = PyCrunchbase()
api = pycb.autocomplete_api()

for entity in api.autocomplete('united').select_collections(
        Collections.Locations.countries, Collections.Locations.cities
).limit(10).execute():
    print(entity.permalink, entity.uuid)

Deleted Entities API

from py_crunchbase import PyCrunchbase, Collections

pycb = PyCrunchbase()

api = pycb.deleted_entities_api()

for page in api.select_collections(
        Collections.Organizations, Collections.People, Collections.FundingRounds, Collections.Events
).order_by_deleted_at().iterate():
    for entity in page:
        print(entity.uuid, entity.deleted_at)

Entities API

from py_crunchbase import PyCrunchbase, Cards

pycb = PyCrunchbase()

org_api = pycb.organizations_api()

cards = Cards.Organization
entity = org_api.get(
    entity_id='tesla-motors',
    field_ids=['website', 'facebook', 'categories', 'short_description', 'founded_on', 'rank_org_company'],
    card_ids=[cards.founders, cards.raised_funding_rounds]
)

print(entity.website, entity.cards)
from py_crunchbase import PyCrunchbase, Cards

pycb = PyCrunchbase()

org_api = pycb.organizations_api()

cards = Cards.Organization
card_list = org_api.get_cards(
    entity_id='sequoia-capital',
    card_id=cards.participated_investments,
    card_field_ids=['announced_on', 'funding_round_money_raised', 'organization_identifier', 'partner_identifiers'],
    order_by=('funding_round_money_raised', 'desc')
)

for card in card_list:
    print(card.uuid)

Extras

Entities

Each Crunchbase Entity has its own class and can be accessed through Entities

from py_crunchbase import Entities

Organization = Entities.Organization
Person = Entities.Person

Entity classes can be extended through a decorator

from py_crunchbase import Entities
from py_crunchbase.decorators import override_entity

@override_entity(Entities.Organization)
class CustomOrganization(Entities.Organization):
    pass

# now Entities.Organization will return CustomOrganization

Cards

Each Entity class defines its own cards (if any) and can be accessed through Cards

from py_crunchbase import Cards

OrgCards = Cards.Organization
print(OrgCards.investors)
print(OrgCards.founders)

# all available Org cards
print(OrgCards.all())

Collections

Collections are also defined in Entity class and can be accessed through Collections

from py_crunchbase import Collections

OrgCol = Collections.Organizations
print(OrgCol.companies)
print(OrgCol.schools)

Exception Handling

There are two ways to catch exceptions

from py_crunchbase import PyCrunchbase, CrunchbaseAPIException

pycb = PyCrunchbase()
api = pycb.autocomplete_api()

try:
    entities = api.autocomplete('box').limit(15).execute()
except api.Exception:
    pass

# OR through CrunchbaseAPIException

try:
    entities = api.autocomplete('box').limit(15).execute()
except CrunchbaseAPIException:
    pass

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

About

A python client for Crunchbase's REST API

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages