mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-29 13:32:08 +00:00
Add more docstrings | @the-praxs
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
"""Package Builder Class."""
|
||||
|
||||
import builtins
|
||||
import shutil
|
||||
import subprocess
|
||||
@@ -531,7 +533,6 @@ class MethodDefinition:
|
||||
od: OrderedDict[str, Parameter], model_name: Optional[str] = None
|
||||
) -> OrderedDict[str, Parameter]:
|
||||
"""Add the field description to the param signature."""
|
||||
|
||||
if model_name:
|
||||
available_fields = (
|
||||
get_provider_interface()
|
||||
@@ -561,6 +562,7 @@ class MethodDefinition:
|
||||
def build_func_params(
|
||||
parameter_map: Dict[str, Parameter], model_name: Optional[str] = None
|
||||
) -> str:
|
||||
"""Build the function params."""
|
||||
od = MethodDefinition.format_params(parameter_map=parameter_map)
|
||||
MethodDefinition.add_field_descriptions(
|
||||
od=od, model_name=model_name
|
||||
@@ -611,6 +613,7 @@ class MethodDefinition:
|
||||
return_type: type,
|
||||
model_name: Optional[str] = None,
|
||||
) -> str:
|
||||
"""Build the command method signature."""
|
||||
func_params = MethodDefinition.build_func_params(parameter_map, model_name)
|
||||
func_returns = MethodDefinition.build_func_returns(return_type)
|
||||
code = "\n @filter_call"
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
"""OpenBB Provider Abstract Class."""
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
"""The OpenBB Standardized Data Model."""
|
||||
from pydantic import BaseModel, Extra
|
||||
|
||||
|
||||
@@ -5,8 +6,11 @@ class Data(BaseModel):
|
||||
"""The OpenBB Standardized Data Model."""
|
||||
|
||||
def __repr__(self):
|
||||
"""Return a string representation of the object."""
|
||||
return f"{self.__class__.__name__}({', '.join([f'{k}={v}' for k, v in self.dict().items()])})"
|
||||
|
||||
class Config:
|
||||
"""Pydantic configuration."""
|
||||
|
||||
extra = Extra.allow
|
||||
allow_population_by_field_name = True
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""Abstract class for providers."""
|
||||
"""Provider Abstract Class."""
|
||||
|
||||
from typing import Dict, List, Optional, Type
|
||||
|
||||
@@ -6,8 +6,7 @@ from openbb_provider.abstract.fetcher import Fetcher
|
||||
|
||||
|
||||
class Provider:
|
||||
"""This class serves as provider extensions entry point and must be
|
||||
created by each provider."""
|
||||
"""Serves as provider extension entry point and must be created by each provider."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
"""The OpenBB Standardized QueryParams Model that holds the query input parameters."""
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
@@ -5,7 +6,10 @@ class QueryParams(BaseModel):
|
||||
"""The OpenBB Standardized QueryParams Model that holds the query input parameters."""
|
||||
|
||||
class Config:
|
||||
"""Pydantic Config."""
|
||||
|
||||
allow_population_by_field_name = True
|
||||
|
||||
def __repr__(self):
|
||||
"""Return the string representation of the QueryParams object."""
|
||||
return f"{self.__class__.__name__}({', '.join([f'{k}={v}' for k, v in self.dict().items()])})"
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
"""Query executor module."""
|
||||
from typing import Any, Dict, Optional, Type
|
||||
|
||||
from openbb_provider.abstract.fetcher import Fetcher, GenericDataType
|
||||
@@ -6,6 +7,8 @@ from openbb_provider.registry import Registry, RegistryLoader
|
||||
|
||||
|
||||
class ProviderError(Exception):
|
||||
"""Exception raised for errors in the provider."""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
@@ -13,6 +16,7 @@ class QueryExecutor:
|
||||
"""Class to execute queries from providers."""
|
||||
|
||||
def __init__(self, registry: Optional[Registry] = None) -> None:
|
||||
"""Initialize the query executor."""
|
||||
self.registry = registry or RegistryLoader.from_extensions()
|
||||
|
||||
def get_provider(self, provider_name: str) -> Provider:
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"""Provider Registry Module."""
|
||||
|
||||
from typing import Dict
|
||||
|
||||
import importlib_metadata
|
||||
@@ -6,26 +8,34 @@ from openbb_provider.abstract.provider import Provider
|
||||
|
||||
|
||||
class Registry:
|
||||
"""Class to maintain registry of providers"""
|
||||
"""Maintain registry of providers."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""Initialize the registry."""
|
||||
self._providers: Dict[str, Provider] = {}
|
||||
|
||||
@property
|
||||
def providers(self):
|
||||
"""Return a dictionary of providers."""
|
||||
return self._providers
|
||||
|
||||
def include_provider(self, provider: Provider) -> None:
|
||||
"""Include a provider in the registry."""
|
||||
self._providers[provider.name.lower()] = provider
|
||||
|
||||
|
||||
class LoadingError(Exception):
|
||||
"""Error loading providers."""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class RegistryLoader:
|
||||
"""Load providers from entry points."""
|
||||
|
||||
@staticmethod
|
||||
def from_extensions() -> Registry:
|
||||
"""Load providers from entry points."""
|
||||
registry = Registry()
|
||||
for entry_point in importlib_metadata.entry_points(
|
||||
group="openbb_provider_extension"
|
||||
|
||||
@@ -14,6 +14,7 @@ class RegistryMap:
|
||||
"""Class to store information about providers in the registry."""
|
||||
|
||||
def __init__(self, registry: Optional[Registry] = None) -> None:
|
||||
"""Initialize Registry Map."""
|
||||
self._registry = registry or RegistryLoader.from_extensions()
|
||||
self._required_credentials = self._get_required_credentials(self._registry)
|
||||
self._available_providers = self._get_available_providers(self._registry)
|
||||
@@ -42,6 +43,7 @@ class RegistryMap:
|
||||
|
||||
@property
|
||||
def return_map(self) -> MapType:
|
||||
"""Get provider registry return map."""
|
||||
return self._return_map
|
||||
|
||||
@property
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
"""OpenBB Provider Package."""
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""Base models for OpenBB Provider. """
|
||||
"""Base models for OpenBB Provider."""
|
||||
from typing import List, Literal, Optional, Union
|
||||
|
||||
from pydantic import BaseModel, Field, NonNegativeInt, validator
|
||||
@@ -8,16 +8,21 @@ from openbb_provider.utils.descriptions import QUERY_DESCRIPTIONS
|
||||
|
||||
|
||||
class BaseSymbol(BaseModel):
|
||||
"""Base model for symbol query params."""
|
||||
|
||||
symbol: str = Field(description=QUERY_DESCRIPTIONS.get("symbol", ""))
|
||||
|
||||
@validator("symbol", pre=True, check_fields=False, always=True)
|
||||
def upper_symbol(cls, v: Union[str, List[str], set[str]]):
|
||||
"""Convert symbol to uppercase."""
|
||||
if isinstance(v, str):
|
||||
return v.upper()
|
||||
return ",".join([symbol.upper() for symbol in list(v)])
|
||||
|
||||
|
||||
class FinancialStatementQueryParams(QueryParams, BaseSymbol):
|
||||
"""Base model for financial statement query params."""
|
||||
|
||||
period: Literal["annually", "quarterly"] = Field(
|
||||
default="annually", description=QUERY_DESCRIPTIONS.get("period", "")
|
||||
)
|
||||
|
||||
@@ -36,7 +36,7 @@ class HistoricalDividendsData(Data):
|
||||
|
||||
@validator("declaration_date", pre=True, check_fields=False)
|
||||
def declaration_date_validate(cls, v: str): # pylint: disable=E0213
|
||||
"""Declaration date validator."""
|
||||
"""Validate declaration date."""
|
||||
if not isinstance(v, str):
|
||||
return v
|
||||
return dateType.fromisoformat(v) if v else None
|
||||
|
||||
@@ -28,7 +28,6 @@ def most_recent_quarter(base: dateType = dateType.today()) -> dateType:
|
||||
date : date
|
||||
The most recent quarter date.
|
||||
"""
|
||||
|
||||
base = min(base, dateType.today()) # This prevents dates from being in the future
|
||||
exacts = [(3, 31), (6, 30), (9, 30), (12, 31)]
|
||||
for exact in exacts:
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
"""OpenBB Provider Utils."""
|
||||
|
||||
@@ -5,6 +5,7 @@ import re
|
||||
from typing import Callable, Dict, List, Optional, Type, Union
|
||||
|
||||
import requests
|
||||
|
||||
from openbb_provider.abstract.fetcher import DataType, ProviderDataType
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user