Package: ncbi-datasets-pylib
NCBI Datasetsis a new resource that lets you easily gather data from across NCBI databases.Find and download sequence, annotation and metadata for genes and genomes using this python library with ourRESTful API.This Python library is automatically generated by theOpenAPI Generator project.Build package: org.openapitools.codegen.languages.PythonClientCodegenRequirementsPython >= 3.7InstallationTo install the pre-built python package, create a virtual environment and use pip:python-mvenvve/sourceve/bin/activate
pipinstallncbi-datasets-pylibGetting StartedPlease follow the installation procedure above and then run the following:importtimeimportncbi.datasets.openapifrompprintimportpprintfromncbi.datasets.openapi.apiimportgene_apifromncbi.datasets.openapi.model.rpc_statusimportRpcStatusfromncbi.datasets.openapi.model.v1_download_summaryimportV1DownloadSummaryfromncbi.datasets.openapi.model.v1_fastaimportV1Fastafromncbi.datasets.openapi.model.v1_gene_dataset_requestimportV1GeneDatasetRequestfromncbi.datasets.openapi.model.v1_gene_dataset_request_content_typeimportV1GeneDatasetRequestContentTypefromncbi.datasets.openapi.model.v1_gene_dataset_request_sort_fieldimportV1GeneDatasetRequestSortFieldfromncbi.datasets.openapi.model.v1_gene_matchimportV1GeneMatchfromncbi.datasets.openapi.model.v1_gene_metadataimportV1GeneMetadatafromncbi.datasets.openapi.model.v1_organismimportV1Organismfromncbi.datasets.openapi.model.v1_organism_query_request_tax_rank_filterimportV1OrganismQueryRequestTaxRankFilterfromncbi.datasets.openapi.model.v1_ortholog_request_content_typeimportV1OrthologRequestContentTypefromncbi.datasets.openapi.model.v1_ortholog_setimportV1OrthologSetfromncbi.datasets.openapi.model.v1_sci_name_and_idsimportV1SciNameAndIdsfromncbi.datasets.openapi.model.v1_sort_directionimportV1SortDirection# Defining the host is optional and defaults to https://api.ncbi.nlm.nih.gov/datasets/v1# See configuration.py for a list of all supported configuration parameters.configuration=ncbi.datasets.openapi.Configuration(host="https://api.ncbi.nlm.nih.gov/datasets/v1")# The client must configure the authentication and authorization parameters# in accordance with the API server security policy.# Examples for each auth method are provided below, use the example that# satisfies your auth use case.# Configure API key authorization: ApiKeyAuthHeaderconfiguration.api_key['ApiKeyAuthHeader']='YOUR_API_KEY'# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed# configuration.api_key_prefix['ApiKeyAuthHeader'] = 'Bearer'# Enter a context with an instance of the API clientwithncbi.datasets.openapi.ApiClient(configuration)asapi_client:# Create an instance of the API classapi_instance=gene_api.GeneApi(api_client)gene_ids=[59067,]# [int] | NCBI gene idsinclude_annotation_type=[V1Fasta("FASTA_UNSPECIFIED"),]# [V1Fasta] | Select additional types of annotation to include in the data package.  If unset, no annotation is provided. (optional)fasta_filter=["fasta_filter_example",]# [str] | Limit the FASTA sequences in the datasets package to these transcript and protein accessions (optional)filename="ncbi_dataset.zip"# str | Output file name. (optional) (default to "ncbi_dataset.zip")try:# Get a gene dataset by gene IDapi_response=api_instance.download_gene_package(gene_ids,include_annotation_type=include_annotation_type,fasta_filter=fasta_filter,filename=filename)pprint(api_response)exceptncbi.datasets.openapi.ApiExceptionase:print("Exception when calling GeneApi->download_gene_package:%s\n"%e)Documentation for API EndpointsFor detailed documentation of API endpoints, see ourGitHub page.NCBI Datasets command-line toolAlternatively, you may be interested in trying the NCBI Datasets command-line tools, datasets and dataformat.Find out more about our command line tools in ourdocumentation.