Skip to main content

BacDive-API - Programmatic Access to the BacDive Database

Project description

BacDive API v2

Using the BacDive API does not require registration anymore, but the usage of BacDive data is only permitted when in compliance with the BacDive terms of use. See About BacDive for details.

import bacdive

client = bacdive.BacdiveClient()

# [optional] You may define the search type as one of the following: 
# 'exact' (default), 'contains', 'startswith', 'endswith'
client.setSearchType('exact')

# The search method fetches all BacDive-IDs matching your query
# and returns the number of IDs found
count = client.search(taxonomy='Bacillus subtilis subtilis')
print(count, 'strains found.')

# the retrieve method lets you iterate over all strains
# and returns the full entry as dict
# Entries can be further filtered using a list of keys (e.g. ['keywords'])
for strain in client.retrieve():
    print(strain)

Example queries:

# Search by BacDive-IDs (either semicolon separated or as list):
query = {"id": 24493}
query = {"id": "24493;12;132485"}
query = {"id": [24493, 12, 132485]}

# Search by culture collection number
query = {"culturecolno": "DSM 26640"}
# New in v1.0: Search by culture collection number with multiple numbers:
query = {"culturecolno": ["DSM 26640", "DSM 26646"]}
query = {"culturecolno": "DSM 26640;DSM 26646"} # semicolon may be used as separator

# Search by culture collection number with search type 'startswith':
client.setSearchType('startswith')
query = {"culturecolno": "DSM"}

# Search by taxonomy (either as full name or as list):
# With genus name, species epithet (optional), and subspecies (optional).
query = {"taxonomy": "Bacillus subtilis subsp. subtilis"}
query = {"taxonomy": ("Escherichia", "coli")}

# Search by 16S sequence accession numbers:
query = {"16s": "AF000162"}
# New in v1.0: Search by 16S sequence with multiple sequence accession numbers:
query = {"16s": ["AB681963", "JN566021", "AY027686"]}
# New in v1.0: Search by 16S sequence with search type 'startswith':
client.setSearchType('startswith')
query = {"16s": "AB"}

# Search by genome sequence accession numbers:
query = {"genome": "GCA_006094295"}
# New in v1.0: Search by genome sequence with multiple sequence accession numbers:
query = {"genome": ["GCA_003332855", "GCA_024623325", "GCA_017377855"]}
# New in v1.0: Search by genome sequence with search type 'startswith':
client.setSearchType('startswith')
query = {"genome": "DSM"}


# run query
client.search(**query)

Filtering

Results from the retrieve Method of both clients can be further filtered. The result contains a list of matched keyword dicts:

filter=['keywords', 'culture collection no.']
result = client.retrieve(filter)
print({k:v for x in result for k,v in x.items()})

The printed result will look like this:

{'1161': [{'keywords': ['human pathogen', 'Bacteria']},
          {'culture collection no.': 'DSM 4393, pC194, SB202'}],
 '1162': [{'keywords': ['human pathogen', 'Bacteria']},
          {'culture collection no.': 'DSM 4514, ATCC 37015, BD170, NCIB 11624, '
                                     'pUB110'}],
 '1163': [{'keywords': ['human pathogen', 'Bacteria']},
          {'culture collection no.': 'DSM 4554, ATCC 37128, BGSC 1E18, pE194'}],
 '1164': [{'keywords': 'Bacteria'},
          {'culture collection no.': 'DSM 4750, 1E7, BGSC 1E7, pE194-cop6'}],
...

Hints for more advanced queries

If you have more advanced queries that are currently not covered by the API, we recommend you to use the BacDive Advanced Search, which is very flexible and powerful. You can then download the resulting table as CSV (button at the top right), import the CSV into your Python script, and use the BacDive-IDs to download all relevant information via the API.

New in v0.3

We added AI-based predictions to the BacDive database. Predicted traits are excluded by default. To include them, you have to call the method includePredictions():

client.includePredictions()

You can exclude predictions again by calling:

client.excludePredictions()

New in v1.0

Thanks to phenolophthaleinum for improving the error handling and Joaquim Sardá for improving the BacDive-API and adding new search possibilities.

Examples for search type definitions and array requests are included in the examples above.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bacdive-2.0.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bacdive-2.0.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file bacdive-2.0.0.tar.gz.

File metadata

  • Download URL: bacdive-2.0.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for bacdive-2.0.0.tar.gz
Algorithm Hash digest
SHA256 4056328f36505e9ba27c36f80fe93687917b4fe4856524d8e8061b95e3868e66
MD5 5b9a6b05dd1f8510184723a6fa9d716a
BLAKE2b-256 4c1819c659d983b48edf16f3ca7ed4cbc7d4fab64c111af6362d654359fddb89

See more details on using hashes here.

File details

Details for the file bacdive-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: bacdive-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for bacdive-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d9998ff50bcd2c439e12882bca41f6a8c7f8d998a3cb0b0acab71d42cbc9afdd
MD5 aaca5d8b1d7fa6f3d43d478d59a3468c
BLAKE2b-256 22f0d5add11b54386e0ef5b34178e55d7ae7cbd70eebb519e0b2390268777824

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page