diff --git a/.gitattributes b/.gitattributes index a6344aac8c09253b3b630fb776ae94478aa0275b..8525ffe3eb56d670178659c565019b2a232a4b74 100644 --- a/.gitattributes +++ b/.gitattributes @@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text *.zip filter=lfs diff=lfs merge=lfs -text *.zst filter=lfs diff=lfs merge=lfs -text *tfevents* filter=lfs diff=lfs merge=lfs -text +build/conda/installer/assets/dmg_volume.icns filter=lfs diff=lfs merge=lfs -text +build/conda/installer/assets/Installer_vertical2.bmp filter=lfs diff=lfs merge=lfs -text diff --git a/assets/README.md b/assets/README.md new file mode 100644 index 0000000000000000000000000000000000000000..85a39728b364ff9eff5d05074811e414af681009 --- /dev/null +++ b/assets/README.md @@ -0,0 +1,5 @@ +# Assets + +This folder should hold assets read by OpenBB applications, such as OpenBB Hub or marketing website. + +The goal is to be more explicit about which assets are being used externally and cannot be deleted before checking where they are used. diff --git a/assets/extensions/obbject.json b/assets/extensions/obbject.json new file mode 100644 index 0000000000000000000000000000000000000000..5c168e67db8025a0ea417f6d8393cf40af5ffa7e --- /dev/null +++ b/assets/extensions/obbject.json @@ -0,0 +1,7 @@ +[ + { + "packageName": "openbb-charting", + "optional": true, + "description": "Create custom charts from OBBject data." + } +] \ No newline at end of file diff --git a/assets/extensions/provider.json b/assets/extensions/provider.json new file mode 100644 index 0000000000000000000000000000000000000000..1bf30ca6b76666f29b18fa182d181016e7c44118 --- /dev/null +++ b/assets/extensions/provider.json @@ -0,0 +1,316 @@ +[ + { + "packageName": "openbb-alpha-vantage", + "optional": true, + "reprName": "Alpha Vantage", + "description": "Alpha Vantage provides realtime and historical\nfinancial market data through a set of powerful and developer-friendly data APIs\nand spreadsheets. From traditional asset classes (e.g., stocks, ETFs, mutual funds)\nto economic indicators, from foreign exchange rates to commodities,\nfrom fundamental data to technical indicators, Alpha Vantage\nis your one-stop-shop for enterprise-grade global market data delivered through\ncloud-based APIs, Excel, and Google Sheets. ", + "credentials": [ + "alpha_vantage_api_key" + ], + "deprecatedCredentials": { + "API_KEY_ALPHAVANTAGE": "alpha_vantage_api_key" + }, + "website": "https://www.alphavantage.co", + "instructions": "Go to: https://www.alphavantage.co/support/#api-key\n\n![AlphaVantage](https://user-images.githubusercontent.com/46355364/207820936-46c2ba00-81ff-4cd3-98a4-4fa44412996f.png)\n\nFill out the form, pass Captcha, and click on, \"GET FREE API KEY\"." + }, + { + "packageName": "openbb-benzinga", + "optional": false, + "reprName": "Benzinga", + "description": "Benzinga is a financial data provider that offers an API\nfocused on information that moves the market.", + "credentials": [ + "benzinga_api_key" + ], + "website": "https://www.benzinga.com" + }, + { + "packageName": "openbb-biztoc", + "optional": true, + "reprName": "BizToc", + "description": "BizToc uses Rapid API for its REST API.\nYou may sign up for your free account at https://rapidapi.com/thma/api/biztoc.\n\nThe Base URL for all requests is:\n\n https://biztoc.p.rapidapi.com/\n\nIf you're not a developer but would still like to use Biztoc outside of the main website,\nwe've partnered with OpenBB, allowing you to pull in BizToc's news stream in their Terminal.", + "credentials": [ + "biztoc_api_key" + ], + "deprecatedCredentials": { + "API_BIZTOC_TOKEN": "biztoc_api_key" + }, + "website": "https://api.biztoc.com", + "instructions": "The BizToc API is hosted on RapidAPI. To set up, go to: https://rapidapi.com/thma/api/biztoc.\n\n![biztoc0](https://github.com/marban/OpenBBTerminal/assets/18151143/04cdd423-f65e-4ad8-ad5a-4a59b0f5ddda)\n\nIn the top right, select 'Sign Up'. After answering some questions, you will be prompted to select one of their plans.\n\n![biztoc1](https://github.com/marban/OpenBBTerminal/assets/18151143/9f3b72ea-ded7-48c5-aa33-bec5c0de8422)\n\nAfter signing up, navigate back to https://rapidapi.com/thma/api/biztoc. If you are logged in, you will see a header called X-RapidAPI-Key.\n\n![biztoc2](https://github.com/marban/OpenBBTerminal/assets/18151143/0f3b6c91-07e0-447a-90cd-a9e23522929f)" + }, + { + "packageName": "openbb-bls", + "optional": false, + "reprName": "Bureau of Labor Statistics' (BLS) Public Data API", + "description": "The Bureau of Labor Statistics' (BLS) Public Data Application Programming Interface (API) gives the public access to economic data from all BLS programs. It is the Bureau's hope that talented developers and programmers will use the BLS Public Data API to create original, inventive applications with published BLS data.", + "credentials": [ + "bls_api_key" + ], + "website": "https://www.bls.gov/developers/api_signature_v2.htm", + "instructions": "Sign up for a free API key here: https://data.bls.gov/registrationEngine/" + }, + { + "packageName": "openbb-cboe", + "optional": true, + "reprName": "Chicago Board Options Exchange (CBOE)", + "description": "Cboe is the world's go-to derivatives and exchange network,\ndelivering cutting-edge trading, clearing and investment solutions to people\naround the world.", + "credentials": [], + "website": "https://www.cboe.com" + }, + { + "packageName": "openbb-cftc", + "optional": false, + "reprName": "Commodity Futures Trading Commission (CFTC) Public Reporting API", + "description": "The mission of the Commodity Futures Trading Commission (CFTC) is to promote the integrity,\n resilience, and vibrancy of the U.S. derivatives markets through sound regulation.", + "credentials": [ + "cftc_app_token" + ], + "website": "https://cftc.gov/", + "instructions": "Credentials are not required, but your IP address may be subject to throttling limits.\n API requests made using an application token are not throttled.\n Create an account here: https://evergreen.data.socrata.com/signup\n and then generate the app_token by signing in with the credentials\n here: https://publicreporting.cftc.gov/profile/edit/developer_settings." + }, + { + "packageName": "openbb-deribit", + "optional": true, + "reprName": "Deribit Public Data", + "description": "Unofficial Python client for public data published by Deribit.", + "credentials": [], + "website": "https://deribit.com/", + "instructions": "This provider does not require any credentials and is not meant for trading." + }, + { + "packageName": "openbb-ecb", + "optional": true, + "reprName": "European Central Bank (ECB)", + "description": "The ECB Data Portal provides access to all official ECB statistics.\nThe portal also provides options to download data and comprehensive metadata for each dataset.\nStatistical publications and dashboards offer a compilation of key data on selected topics.", + "credentials": [], + "website": "https://data.ecb.europa.eu" + }, + { + "packageName": "openbb-econdb", + "optional": false, + "reprName": "EconDB", + "description": "The mission of the company is to process information in ways that\nfacilitate understanding of the economic situation at different granularity levels.\n\nThe sources of data include official statistics agencies and so-called alternative\ndata sources where we collect direct observations of the market and generate\naggregate statistics.", + "credentials": [ + "econdb_api_key" + ], + "website": "https://econdb.com" + }, + { + "packageName": "openbb-federal-reserve", + "optional": false, + "reprName": "Federal Reserve (FED)", + "description": "Access data provided by the Federal Reserve System, the Central Bank of the United States.", + "credentials": [], + "website": "https://www.federalreserve.gov/data.htm" + }, + { + "packageName": "openbb-finra", + "optional": true, + "reprName": "Financial Industry Regulatory Authority (FINRA)", + "description": "FINRA Data provides centralized access to the abundance of data FINRA\nmakes available to the public, media, researchers and member firms.", + "credentials": [], + "website": "https://www.finra.org/finra-data" + }, + { + "packageName": "openbb-finviz", + "optional": true, + "reprName": "FinViz", + "description": "Unofficial Finviz API - https://github.com/lit26/finvizfinance/releases", + "credentials": [], + "website": "https://finviz.com" + }, + { + "packageName": "openbb-fmp", + "optional": false, + "reprName": "Financial Modeling Prep (FMP)", + "description": "Financial Modeling Prep is a new concept that informs you about\nstock market information (news, currencies, and stock prices).", + "credentials": [ + "fmp_api_key" + ], + "deprecatedCredentials": { + "API_KEY_FINANCIALMODELINGPREP": "fmp_api_key" + }, + "website": "https://financialmodelingprep.com", + "instructions": "Go to: https://site.financialmodelingprep.com/developer/docs\n\n![FinancialModelingPrep](https://user-images.githubusercontent.com/46355364/207821920-64553d05-d461-4984-b0fe-be0368c71186.png)\n\nClick on, \"Get my API KEY here\", and sign up for a free account.\n\n![FinancialModelingPrep](https://user-images.githubusercontent.com/46355364/207822184-a723092e-ef42-4f87-8c55-db150f09741b.png)\n\nWith an account created, sign in and navigate to the Dashboard, which shows the assigned token. by pressing the \"Dashboard\" button which will show the API key.\n\n![FinancialModelingPrep](https://user-images.githubusercontent.com/46355364/207823170-dd8191db-e125-44e5-b4f3-2df0e115c91d.png)" + }, + { + "packageName": "openbb-fred", + "optional": false, + "reprName": "Federal Reserve Economic Data | St. Louis FED (FRED)", + "description": "Federal Reserve Economic Data is a database maintained by the\nResearch division of the Federal Reserve Bank of St. Louis that has more than\n816,000 economic time series from various sources.", + "credentials": [ + "fred_api_key" + ], + "deprecatedCredentials": { + "API_FRED_KEY": "fred_api_key" + }, + "website": "https://fred.stlouisfed.org", + "instructions": "Go to: https://fred.stlouisfed.org\n\n![FRED](https://user-images.githubusercontent.com/46355364/207827137-d143ba4c-72cb-467d-a7f4-5cc27c597aec.png)\n\nClick on, \"My Account\", create a new account or sign in with Google:\n\n![FRED](https://user-images.githubusercontent.com/46355364/207827011-65cdd501-27e3-436f-bd9d-b0d8381d46a7.png)\n\nAfter completing the sign-up, go to \"My Account\", and select \"API Keys\". Then, click on, \"Request API Key\".\n\n![FRED](https://user-images.githubusercontent.com/46355364/207827577-c869f989-4ef4-4949-ab57-6f3931f2ae9d.png)\n\nFill in the box for information about the use-case for FRED, and by clicking, \"Request API key\", at the bottom of the page, the API key will be issued.\n\n![FRED](https://user-images.githubusercontent.com/46355364/207828032-0a32d3b8-1378-4db2-9064-aa1eb2111632.png)" + }, + { + "packageName": "openbb-government-us", + "optional": true, + "reprName": "Data.gov | United States Government", + "description": "Data.gov is the United States government's open data website.\nIt provides access to datasets published by agencies across the federal government.\nData.gov is intended to provide access to government open data to the public, achieve\nagency missions, drive innovation, fuel economic activity, and uphold the ideals of\nan open and transparent government.", + "credentials": [], + "website": "https://data.gov" + }, + { + "packageName": "openbb-imf", + "optional": false, + "reprName": "International Monetary Fund (IMF) Public Data API", + "description": "This provider allows you to access International Monetary Fund data through the IMF Public Data API.", + "credentials": [], + "website": "https://datahelp.imf.org/knowledgebase/articles/667681-using-json-restful-web-service" + }, + { + "packageName": "openbb-intrinio", + "optional": false, + "reprName": "Intrinio", + "description": "Intrinio is a financial data platform that provides real-time and\nhistorical financial market data to businesses and developers through an API.", + "credentials": [ + "intrinio_api_key" + ], + "deprecatedCredentials": { + "API_INTRINIO_KEY": "intrinio_api_key" + }, + "website": "https://intrinio.com", + "instructions": "Go to: https://intrinio.com/starter-plan\n\n![Intrinio](https://user-images.githubusercontent.com/85772166/219207556-fcfee614-59f1-46ae-bff4-c63dd2f6991d.png)\n\nAn API key will be issued with a subscription. Find the token value within the account dashboard." + }, + { + "packageName": "openbb-multpl", + "optional": true, + "description": "Public broad-market data published to https://multpl.com.", + "credentials": [], + "website": "https://www.multpl.com/" + }, + { + "packageName": "openbb-nasdaq", + "optional": true, + "reprName": "NASDAQ", + "description": "Positioned at the nexus of technology and the capital markets, Nasdaq\nprovides premier platforms and services for global capital markets and beyond with\nunmatched technology, insights and markets expertise.", + "credentials": [ + "nasdaq_api_key" + ], + "deprecatedCredentials": { + "API_KEY_QUANDL": "nasdaq_api_key" + }, + "website": "https://data.nasdaq.com", + "instructions": "Go to: https://www.quandl.com\n\n![Quandl](https://user-images.githubusercontent.com/46355364/207823899-208a3952-f557-4b73-aee6-64ac00faedb7.png)\n\nClick on, \"Sign Up\", and register a new account.\n\n![Quandl](https://user-images.githubusercontent.com/46355364/207824214-4b6b2b74-e709-4ed4-adf2-14803e6f3568.png)\n\nFollow the sign-up instructions, and upon completion the API key will be assigned.\n\n![Quandl](https://user-images.githubusercontent.com/46355364/207824664-3c82befb-9c69-42df-8a82-510d85c19a97.png)" + }, + { + "packageName": "openbb-oecd", + "optional": false, + "reprName": "Organization for Economic Co-operation and Development (OECD)", + "description": "OECD Data Explorer includes data and metadata for OECD countries and selected\nnon-member economies.", + "credentials": [], + "website": "https://data-explorer.oecd.org/" + }, + { + "packageName": "openbb-polygon", + "optional": false, + "reprName": "Polygon.io", + "description": "The Polygon.io Stocks API provides REST endpoints that let you query\nthe latest market data from all US stock exchanges. You can also find data on\ncompany financials, stock market holidays, corporate actions, and more.", + "credentials": [ + "polygon_api_key" + ], + "deprecatedCredentials": { + "API_POLYGON_KEY": "polygon_api_key" + }, + "website": "https://polygon.io", + "instructions": "Go to: https://polygon.io\n\n![Polygon](https://user-images.githubusercontent.com/46355364/207825623-fcd7f0a3-131a-4294-808c-754c13e38e2a.png)\n\nClick on, \"Get your Free API Key\".\n\n![Polygon](https://user-images.githubusercontent.com/46355364/207825952-ca5540ec-6ed2-4cef-a0ed-bb50b813932c.png)\n\nAfter signing up, the API Key is found at the bottom of the account dashboard page.\n\n![Polygon](https://user-images.githubusercontent.com/46355364/207826258-b1f318fa-fd9c-41d9-bf5c-fe16722e6601.png)" + }, + { + "packageName": "openbb-sec", + "optional": false, + "reprName": "Securities and Exchange Commission (SEC)", + "description": "SEC is the public listings regulatory body for the United States.", + "credentials": [], + "website": "https://www.sec.gov/data" + }, + { + "packageName": "openbb-seeking-alpha", + "optional": true, + "reprName": "Seeking Alpha", + "description": "Seeking Alpha is a data provider with access to news, analysis, and\nreal-time alerts on stocks.", + "credentials": [], + "website": "https://seekingalpha.com" + }, + { + "packageName": "openbb-stockgrid", + "optional": true, + "reprName": "Stockgrid", + "description": "Stockgrid gives you a detailed view of what smart money is doing.\nGet in depth data about large option blocks being traded, including\nthe sentiment score, size, volume and order type. Stop guessing and\nbuild a strategy around the number 1 factor moving the market: money.", + "credentials": [], + "website": "https://www.stockgrid.io" + }, + { + "packageName": "openbb-tiingo", + "optional": false, + "reprName": "Tiingo", + "description": "A Reliable, Enterprise-Grade Financial Markets API. Tiingo's APIs\npower hedge funds, tech companies, and individuals.", + "credentials": [ + "tiingo_token" + ], + "website": "https://tiingo.com" + }, + { + "packageName": "openbb-tmx", + "optional": true, + "reprName": "TMX", + "description": "Unofficial TMX Data Provider Extension\n TMX Group Companies\n - Toronto Stock Exchange\n - TSX Venture Exchange\n - TSX Trust\n - Montr\u00e9al Exchange\n - TSX Alpha Exchange\n - Shorcan\n - CDCC\n - CDS\n - TMX Datalinx\n - Trayport\n ", + "credentials": [], + "website": "https://www.tmx.com" + }, + { + "packageName": "openbb-tradier", + "optional": true, + "reprName": "Tradier", + "description": "Tradier provides a full range of services in a scalable, secure,\nand easy-to-use REST-based API for businesses and individual developers.\nFast, secure, simple. Start in minutes.\nGet access to trading, account management, and market-data for\nTradier Brokerage accounts through our APIs.", + "credentials": [ + "tradier_api_key", + "tradier_account_type" + ], + "deprecatedCredentials": { + "API_TRADIER_TOKEN": "tradier_api_key" + }, + "website": "https://tradier.com", + "instructions": "Go to: https://documentation.tradier.com\n\n![Tradier](https://user-images.githubusercontent.com/46355364/207829178-a8bba770-f2ea-4480-b28e-efd81cf30980.png)\n\nClick on, \"Open Account\", to start the sign-up process. After the account has been setup, navigate to [Tradier Broker Dash](https://dash.tradier.com/login?redirect=settings.api) and create the application. Request a sandbox access token." + }, + { + "packageName": "openbb-tradingeconomics", + "optional": false, + "reprName": "Trading Economics", + "description": "Trading Economics provides its users with accurate information for\n196 countries including historical data and forecasts for more than 20 million economic\nindicators, exchange rates, stock market indexes, government bond yields and commodity\nprices. Our data for economic indicators is based on official sources, not third party\ndata providers, and our facts are regularly checked for inconsistencies.\nTrading Economics has received nearly 2 billion page views from all around the\nworld.", + "credentials": [ + "tradingeconomics_api_key" + ], + "website": "https://tradingeconomics.com" + }, + { + "packageName": "openbb-us-eia", + "optional": false, + "reprName": "U.S. Energy Information Administration (EIA) Open Data and API", + "description": "The U.S. Energy Information Administration is committed to its free and open data by making it available through an Application Programming Interface (API) and its open data tools. See https://www.eia.gov/opendata/ for more information.", + "credentials": [ + "eia_api_key" + ], + "website": "https://eia.gov/", + "instructions": "Credentials are required for functions calling the EIA's API.\n Register for a free key here: https://www.eia.gov/opendata/register.php" + }, + { + "packageName": "openbb-wsj", + "optional": true, + "reprName": "Wall Street Journal (WSJ)", + "description": "WSJ (Wall Street Journal) is a business-focused, English-language\ninternational daily newspaper based in New York City. The Journal is published six\ndays a week by Dow Jones & Company, a division of News Corp, along with its Asian\nand European editions. The newspaper is published in the broadsheet format and\nonline. The Journal has been printed continuously since its inception on\nJuly 8, 1889, by Charles Dow, Edward Jones, and Charles Bergstresser.\nThe WSJ is the largest newspaper in the United States, by circulation.\n ", + "credentials": [], + "website": "https://www.wsj.com" + }, + { + "packageName": "openbb-yfinance", + "optional": false, + "reprName": "Yahoo Finance", + "description": "Yahoo! Finance is a web-based platform that offers financial news,\ndata, and tools for investors and individuals interested in tracking and analyzing\nfinancial markets and assets.", + "credentials": [], + "website": "https://finance.yahoo.com" + } +] \ No newline at end of file diff --git a/assets/extensions/router.json b/assets/extensions/router.json new file mode 100644 index 0000000000000000000000000000000000000000..2c1fb008cac254417ddf0bf8afdfc68113de4984 --- /dev/null +++ b/assets/extensions/router.json @@ -0,0 +1,72 @@ +[ + { + "packageName": "openbb-commodity", + "optional": false, + "description": "Commodity market data." + }, + { + "packageName": "openbb-crypto", + "optional": false, + "description": "Cryptocurrency market data." + }, + { + "packageName": "openbb-currency", + "optional": false, + "description": "Foreign exchange (FX) market data." + }, + { + "packageName": "openbb-derivatives", + "optional": false, + "description": "Derivatives market data." + }, + { + "packageName": "openbb-econometrics", + "optional": true, + "description": "Econometrics analysis tools." + }, + { + "packageName": "openbb-economy", + "optional": false, + "description": "Economic data." + }, + { + "packageName": "openbb-equity", + "optional": false, + "description": "Equity market data." + }, + { + "packageName": "openbb-etf", + "optional": false, + "description": "Exchange Traded Funds market data." + }, + { + "packageName": "openbb-fixedincome", + "optional": false, + "description": "Fixed Income market data." + }, + { + "packageName": "openbb-index", + "optional": false, + "description": "Indices data." + }, + { + "packageName": "openbb-news", + "optional": false, + "description": "Financial market news data." + }, + { + "packageName": "openbb-quantitative", + "optional": true, + "description": "Quantitative analysis tools." + }, + { + "packageName": "openbb-regulators", + "optional": false, + "description": "Financial market regulators data." + }, + { + "packageName": "openbb-technical", + "optional": true, + "description": "Technical Analysis tools." + } +] \ No newline at end of file diff --git a/assets/scripts/generate_extension_data.py b/assets/scripts/generate_extension_data.py new file mode 100644 index 0000000000000000000000000000000000000000..2962a70ca7be3df1e394abf0db0d93238336b863 --- /dev/null +++ b/assets/scripts/generate_extension_data.py @@ -0,0 +1,126 @@ +"""Generate assets from modules.""" + +from importlib import import_module +from json import dump +from pathlib import Path +from typing import Any, Dict, List + +from poetry.core.pyproject.toml import PyProjectTOML + +THIS_DIR = Path(__file__).parent +OPENBB_PLATFORM_PATH = Path(THIS_DIR, "..", "..", "openbb_platform") +PROVIDERS_PATH = OPENBB_PLATFORM_PATH / "providers" +EXTENSIONS_PATH = OPENBB_PLATFORM_PATH / "extensions" +OBBJECT_EXTENSIONS_PATH = OPENBB_PLATFORM_PATH / "obbject_extensions" + +OPENBB_PLATFORM_TOML = PyProjectTOML(OPENBB_PLATFORM_PATH / "pyproject.toml") + + +def to_title(string: str) -> str: + """Format string to title.""" + return " ".join(string.split("_")).title() + + +def get_packages(path: Path, plugin_key: str) -> Dict[str, Any]: + """Get packages.""" + SKIP = ["tests", "__pycache__"] + folders = [f for f in path.glob("*") if f.is_dir() and f.stem not in SKIP] + packages: Dict[str, Any] = {} + for f in folders: + pyproject = PyProjectTOML(Path(f, "pyproject.toml")) + + if not pyproject.data: + continue + + poetry = pyproject.data["tool"]["poetry"] + name = poetry["name"] + plugin = poetry.get("plugins", {}).get(plugin_key) + packages[name] = {"plugin": list(plugin.values())[0] if plugin else ""} + return packages + + +def write(filename: str, data: Any): + """Write to json.""" + with open(Path(THIS_DIR, "..", "extensions", f"{filename}.json"), "w") as json_file: + dump(data, json_file, indent=4) + + +def to_camel(string: str): + """Convert string to camel case.""" + components = string.split("_") + return components[0] + "".join(x.title() for x in components[1:]) + + +def create_item(package_name: str, obj: object, obj_attrs: List[str]) -> Dict[str, Any]: + """Create dictionary item from object attributes.""" + pkg_spec = OPENBB_PLATFORM_TOML.data["tool"]["poetry"]["dependencies"].get( + package_name + ) + optional = pkg_spec.get("optional", False) if isinstance(pkg_spec, dict) else False + item = {"packageName": package_name, "optional": optional} + item.update( + {to_camel(a): getattr(obj, a) for a in obj_attrs if getattr(obj, a) is not None} + ) + return item + + +def generate_provider_extensions() -> None: + """Generate providers_extensions.json.""" + packages = get_packages(PROVIDERS_PATH, "openbb_provider_extension") + data: List[Dict[str, Any]] = [] + obj_attrs = [ + "repr_name", + "description", + "credentials", + "deprecated_credentials", + "website", + "instructions", + ] + + for pkg_name, details in sorted(packages.items()): + plugin = details.get("plugin", "") + file_obj = plugin.split(":") + if len(file_obj) == 2: + file, obj = file_obj[0], file_obj[1] + module = import_module(file) + provider_obj = getattr(module, obj) + data.append(create_item(pkg_name, provider_obj, obj_attrs)) + write("provider", data) + + +def generate_router_extensions() -> None: + """Generate router_extensions.json.""" + packages = get_packages(EXTENSIONS_PATH, "openbb_core_extension") + data: List[Dict[str, Any]] = [] + obj_attrs = ["description"] + for pkg_name, details in sorted(packages.items()): + plugin = details.get("plugin", "") + file_obj = plugin.split(":") + if len(file_obj) == 2: + file, obj = file_obj[0], file_obj[1] + module = import_module(file) + router_obj = getattr(module, obj) + data.append(create_item(pkg_name, router_obj, obj_attrs)) + write("router", data) + + +def generate_obbject_extensions() -> None: + """Generate obbject_extensions.json.""" + packages = get_packages(OBBJECT_EXTENSIONS_PATH, "openbb_obbject_extension") + data: List[Dict[str, Any]] = [] + obj_attrs = ["description"] + for pkg_name, details in sorted(packages.items()): + plugin = details.get("plugin", "") + file_obj = plugin.split(":") + if len(file_obj) == 2: + file, obj = file_obj[0], file_obj[1] + module = import_module(file) + ext_obj = getattr(module, obj) + data.append(create_item(pkg_name, ext_obj, obj_attrs)) + write("obbject", data) + + +if __name__ == "__main__": + generate_provider_extensions() + generate_router_extensions() + generate_obbject_extensions() diff --git a/build/conda/README.md b/build/conda/README.md new file mode 100644 index 0000000000000000000000000000000000000000..af131a5ee1c4ae7dfcc588942f20d83fe5844c1a --- /dev/null +++ b/build/conda/README.md @@ -0,0 +1,38 @@ +# OpenBB Platform Installer + +The code in this folder creates a packaged installer for the OpenBB Platform, using Conda Constructor. + +The installers can be created for Windows (.exe), macOS (.pkg). + +The installer is distributed with a Conda environment that contains Python and package management tools. + +The dependencies required to run the application are installed from PyPI by the constructor's post_install script. They are installed by poetry and are defined in the `installer/assets/openbb_platform_installer/pyproject.toml` file. + +The version of Python is defined in the `construct.yaml` file. It is set for 3.12. + +## Build Instructions + +**In order to build the installer, conda should be already installed and initialized your current shell profile.** + +Navigate into the `build/conda` folder and then begin. + +1. Create the Conda environment. + - `conda env create --file environments/constructor.yml` +2. Activate the environment. + - `conda activate constructor` +3. Build the installer. + - `constructor installer/.` + +## For when we have a full NSIS + +To check nsis file - run + +```batch +miniconda3\envs\constructor\NSIS\makensis.exe /V2 assets\installer.nsi +``` + +gives better output for errors + +```batch +miniconda3\envs\constructor\NSIS\makensis.exe /V4 assets\installer.nsi +``` diff --git a/build/conda/environments/constructor.yml b/build/conda/environments/constructor.yml new file mode 100644 index 0000000000000000000000000000000000000000..21d8d69aec129fb79670ae5e89c27ac29b3b5b6a --- /dev/null +++ b/build/conda/environments/constructor.yml @@ -0,0 +1,10 @@ +name: constructor +channels: + - conda-forge + - defaults +dependencies: + - conda-build + - constructor>=3.9.3 + - six + - urllib3 + - requests diff --git a/build/conda/installer/README.md b/build/conda/installer/README.md new file mode 100644 index 0000000000000000000000000000000000000000..faa4b01a77e97b79180b6e10ef93dafef5dc8846 --- /dev/null +++ b/build/conda/installer/README.md @@ -0,0 +1,246 @@ +# OpenBB Platform + +Thanks for installing the OpenBB Platform. To get the most out of your experience, we recommend reviewing the contents of this document. + +If you have never used Python before, don't worry, your first time is just a double-click away. The sections below outline everything you need to know for getting started. + +## What Did I Install? + +This is a kitted out development container for Pythonic, open source, financial research. It has everything you need to get started immediately. + +Included is a complete installation of the OpenBB Platform and CLI, along with Conda and Jupyter Notebook, in an isolated Python 3.12 Conda environment. + +If you already have an installation of Conda or Anaconda, the version in this folder will not rely on, interfere, or share base environment paths with, existing versions. + +Tools for managing, updating, and building environments allow you to take full control of your installation, as well as quickly spin up new containers within this project folder. + +Follow the quick start steps below to get started using right away; or, open one of the shortcuts described below. + +If you want to build your own endpoints, connections, and features, try installing the [example extensions](#examples) + +## OpenBB Workspace Quick Start + +- Login to the [OpenBB Hub](https://my.openbb.co) +- Optionally, add API keys for remote authorization on the page [here](https://my.openbb.dev/app/platform/credentials). + - If credentials have been added, from the sidebar, click on 'Personal Access Token'. + - Generate a token and copy the value to the clipboard. +- Optionally, from the sidebar, click on 'Widgets' to filter out any provider extensions or endpoints you wish to exclude. + - Without filtering, there will be well over 300 individual widgets. This will narrow the field and focus on only what you need. + - After configuring, download the file ("widget_settings.json") and save it to, `~/.openbb_platform`. The "Settings" shortcut takes you there. +- Double-click on the `openbb-api` shortcut. +- If you generated a personal access token, paste the values that were copied to the clipboard and hit the return key. + - Enter y/n to persist the downloaded credentials on the local machine for future sessions. + +- By default, the server will be running on: [http://127.0.0.1:6900](http://127.0.0.1:6900) + +- Login to OpenBB Workspace [here](https://pro.openbb.co) +- From the sidebar, click on, "Data Connectors". +- Then click on the button, "Add Data". +- In the pop-up menu, select "Custom Backend". +- Enter a name for the connection - i.e, "OpenBB Platform" +- Enter the address the server is running on - i.e, "http://127.0.0.1:6900" +- **Ensure that "Validate Widgets" is set to "No".** +- Click on the "Test" button. +- Finally, click on the "Add" button. + +The OpenBB Platform API widgets can now be added to any dashboard. For a more detailed version of these instructions, see the documentation page [here](https://docs.openbb.co/pro/custom-backend) + +## Shortcuts + +At the root of the installation folder (where this document is) are shortcuts for launchers and to key file locations. + +- Bash (Windows: CMD): Opens a command line shell with the base Conda environment activated. Activate the OpenBB environment with: + - Mac/Linux: `source activate obb` + - Windows: `conda activate obb` +- Environments: Shortcut to the root "envs" folder, where the `obb` and any created environments are stored. + - "widgets.json" is located in the "assets" subdirectory. +- openbb-api: Opens a Terminal window and launches the OpenBB API, with optional prompts to login with your OpenBB Hub PAT. +- openbb-cli: Opens a Terminal window and launches the OpenBB CLI (formerly OpenBB Terminal). +- openbb-ipython: Opens a Terminal window and starts an IPython session with the OpenBB Platform package imported. +- openbb-notebook: Opens a Terminal window, starts the Jupyter development server, and opens a browser window with the Notebook application. +- OpenBBUserData: Shortcut to the OpenBBUserData folder. Files exported from CLI are saved here. +- Settings: Shortcut to the `~/.openbb_platform` location where `.env` files and `user_settings.json` are stored. + - If you cannot see the ".env" file, set Finder/Explorer to display hidden/system files. +- Update: Opens a Terminal window and updates the OpenBB Platform environment (obb) and packages. + +## Command Line Entry Points + +There are several command line entry points available when either: +- The OpenBB Platform environment (obb) is active. +- The "openbb_platform_installer" package has been installed in the active Python environment. + +### OpenBB Entry Points + +- openbb: Launches the OpenBB CLI. +- openbb-api: Launches the API and accepts select arguments. + - All args/kwargs available to `uvicorn run` are exposed. + - `--login`: True/False. Defeats the login prompt when False. + - `--no-build`: Skips building "widgets.json" +- openbb-build: Runs the build script that generates the static assets for the OpenBB Python interface. + - Run this after installing/uninstalling/updating OpenBB extensions + - Automatically run when `openbb-update` is run. +- openbb-update: Updates the environment packages defined in `pyproject.toml` and `poetry.lock` and rebuilds the OpenBB Python interface. + - Location of Poetry files: "/extensions/openbb_platform_installer" + - Passes all args/kwargs to `poetry install`. + +### Starting The OpenBB Platform API With Optional Arguments + +1. Open the `Bash` (`CMD` on Windows) shortcut. +2. Activate the `obb` environment + - Unix: `source activate obb` + - Windows: `conda activate obb` +3. Run `openbb-api` with `--parameter value` to add any `uvicorn.run` parameter. + +### OpenBB Platform API Over HTTPS + +To run the API over the HTTPS protocol, you must first create a self-signed certificate and the associated key. After steps 1 & 2 above, you can generate the files by entering this to the command line: + +```sh +openssl req -x509 -days 3650 -out localhost.crt -keyout localhost.key -newkey rsa:4096 -nodes -sha256 -subj '/CN=localhost' -extensions EXT -config <( \ + printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth") +``` + +Two files will be created, in the current working directory, that are passed as keyword arguments to the `openbb-api` entry point. + +```sh +openbb-api --ssl_keyfile localhost.key --ssl_certfile localhost.crt +``` + +**Note**: Adjust the command to include the full path to the file if the current working directory is not where they are located. + + +The certificate - `localhost.crt` - will need to be added to system's trust store. The process for this will depend on the operating system and the user account privilege. + +A quick solution is to visit the server's URL, show the details of the warning, and choose to continue anyways. + +Contact the system administrator if you are using a work device and require additional permissions to complete the configuration. + +![This Connection Is Not Private](https://in.norton.com/content/dam/blogs/images/norton/am/this_connection_not_is_private.png) + +## Installed Folder Structure + +At the root of the installation (where this document is), there will be three folders: + +- conda (Windows: This is named after the last folder path if the default was not used) +- extensions +- notebooks + +### Conda + +This is the folder where Conda is installed and all environment data (site-packages, etc.) is stored. The "Environments" shortcuts takes you to the root of the "envs" folder. + +### Extensions + +This folder contains two subfolders: + +### Notebooks + +This folder contains tutorial notebooks with examples for getting started with Python and the OpenBB Platform. They can be opened by launching the `openbb-notebook` shortcut. + +#### examples + +Contains empty example extensions for the three types of OpenBB Platform extensions: + +- Router +- Provider +- OBBject + +To install all three examples in the OpenBB Platform environment, open the Bash/CMD shortcut and enter: + +```console +source activate obb # CMD: conda activate obb +cd extensions/examples +python install_examples.py +``` + +#### openbb_platform_installer + +This is a meta package for installing and managing OpenBB Platform installation within any Python environment. +Poetry is used to update and resolve any dependencies that are defined in the `pyproject.toml` file. + +The `poetry.lock` file is updated every time the `Update` shortcut is run. + +There are several configurations available, via combinations of `--with`, `--without`, and `--only` parameters, when running `poetry install`. + +Choices are: + +- main +- openbb-all +- cli +- notebook + +Each parameter will accept multiple items, but `--without` takes priority for solving for the environment. + +## Uninstallation + +Mac/Linux users can uninstall by deleting the folder, while Windows users can run the Uninstall shortcut. + +The leftover artifacts will include: + +- Global configuration files stored by Poetry, PIP, Conda, and Jupyter. +- Third-party Python package caches and `.env` files. +- Folders: + - ~/.openbb_platform + - ~/OpenBBUserData + +Windows users will also need to remove the parent folder where it was originally installed, after running Uninstall. + +Your OpenBB Hub account can be deleted, along with all associated data, from the Account page in [my.openbb.co](https://my.openbb.co) + +## Additional Information + +### Conda Install vs. PIP Install vs. Poetry Install + +The three ways to install packages may appear to accomplish the same objectives - installing Python packages - but each has a distinctly different purpose. + +An easy way to think about the difference is, both `pip` and `poetry` require an existing Python installation; `conda` installs Python so that you can run `pip install poetry`. + +In general, you use: + +- `conda` + - When a new environment has been created. Packages here can be included in the creation command, `conda create`. + - When the specific package is only distributed through Conda or the `conda-forge` channel. + - When changing the version of Python used within the environment. + - For interactions with the machine code layer of the system - e.g., compilers, and bridges to "outside of Python" land. +- `pip` + - When installing/uninstalling packages to the activated Python environment. + - Resort to `conda install` when packages fail to install, or wheels cannot be built, from PyPI. +- `poetry` + - Installing a local Python package. + - Syncing all package dependencies according to provided specs in `pyproject.toml` and `poetry.lock` files. + - Building and distributing Python packages. + +Conda is for container management and machine code level operations, Poetry resolves the project's dependencies and provides build/distribution tools within the current Python environment, while `pip` is for installing Python packages - typically from [PyPI](https://pypi.org). + +### Documentation Resources + +### OpenBB +- [OpenBB Pro](https://docs.openbb.co/pro) +- [OpenBB Pro Data Connectors](https://docs.openbb.co/pro/data-connector) +- [widgets.json](https://docs.openbb.co/pro/custom-backend/widgets.json) +- [OpenBB Platform](https://docs.openbb.co/platform) +- [OpenBB Platform Quickstart](https://docs.openbb.co/platform/getting_started/quickstart) +- [OpenBB CLI](https://docs.openbb.co/cli) +- [OpenBB User Settings](https://docs.openbb.co/platform/user_guides/settings_and_environment_variables) +- [API Keys and Authorization](https://docs.openbb.co/platform/getting_started/api_keys) +- [REST API Requests](https://docs.openbb.co/platform/getting_started/api_requests) +- [OpenBB Platform Architecture Overview](https://docs.openbb.co/platform/developer_guide/architecture_overview) +- [Create A New Router Extension](https://docs.openbb.co/platform/getting_started/create_new_router_extension) +- [OpenBB Charting](https://github.com/OpenBB-finance/OpenBB/tree/develop/openbb_platform/obbject_extensions/charting#readme) +- [PyWry](https://github.com/OpenBB-finance/pywry) + +### External + +- [python](https://docs.python.org/3/) +- [conda create](https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#managing-environments) +- [pyproject.toml](https://python-poetry.org/docs/pyproject/) +- [requirements.txt](https://pip.pypa.io/en/stable/reference/requirements-file-format/) +- [pip](https://pip.pypa.io/en/stable/) +- [poetry config](https://python-poetry.org/docs/configuration) +- [pydantic](https://docs.pydantic.dev/latest/) +- [uvicorn](https://www.uvicorn.org/) +- [fastapi](https://fastapi.tiangolo.com/) +- [jupyter](https://docs.jupyter.org/en/latest/) +- [pandas](https://pandas.pydata.org/docs/) +- [numpy](https://numpy.org/doc/) +- [Plotly Graph Objects](https://plotly.com/python/graph-objects/) diff --git a/build/conda/installer/assets/Installer_horizontal.bmp b/build/conda/installer/assets/Installer_horizontal.bmp new file mode 100644 index 0000000000000000000000000000000000000000..7de270256996faa5063a43679935999e70b33187 Binary files /dev/null and b/build/conda/installer/assets/Installer_horizontal.bmp differ diff --git a/build/conda/installer/assets/Installer_horizontal2.png b/build/conda/installer/assets/Installer_horizontal2.png new file mode 100644 index 0000000000000000000000000000000000000000..2261c710255e804d79ee3a563691c3565ee59431 Binary files /dev/null and b/build/conda/installer/assets/Installer_horizontal2.png differ diff --git a/build/conda/installer/assets/Installer_vertical2.bmp b/build/conda/installer/assets/Installer_vertical2.bmp new file mode 100644 index 0000000000000000000000000000000000000000..ece8f603384d2f37a9063eede419d216ad3266dd --- /dev/null +++ b/build/conda/installer/assets/Installer_vertical2.bmp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:47b558253268762d87b97e358a103db267e54f9f54a5805d82fcdafaa3093bf3 +size 357254 diff --git a/build/conda/installer/assets/create_shortcut.vbs b/build/conda/installer/assets/create_shortcut.vbs new file mode 100644 index 0000000000000000000000000000000000000000..395da62415c02c39969da4362342d7f1cae25246 --- /dev/null +++ b/build/conda/installer/assets/create_shortcut.vbs @@ -0,0 +1,70 @@ +Set objShell = CreateObject("WScript.Shell") +sdesktopPath = objShell.SpecialFolders("Desktop") + +Set fso = CreateObject("Scripting.FileSystemObject") +prefixPath = objShell.ExpandEnvironmentStrings("%PREFIX%") +userProfilePath = objShell.ExpandEnvironmentStrings("%USERPROFILE%") +currentPath = fso.GetAbsolutePathName(prefixPath) +parentFolder = fso.GetParentFolderName(currentPath) +shortcutFolder = parentFolder + +Set objFSO = CreateObject("Scripting.FileSystemObject") +If Not objFSO.FolderExists(shortcutFolder) Then + objFSO.CreateFolder(shortcutFolder) +End If + +If prefixPath = "%PREFIX%" Or userProfilePath = "%USERPROFILE%" Then + WScript.Echo "Environment variables %PREFIX% or %USERPROFILE% are not set correctly." + WScript.Quit 1 +End If + +Sub CreateShortcut(name, targetPath, iconPath) + Set objShell = CreateObject("WScript.Shell") + Set objShortcut = objShell.CreateShortcut(shortcutFolder & "\" & name & ".lnk") + objShortcut.TargetPath = objShell.ExpandEnvironmentStrings(targetPath) + objShortcut.IconLocation = objShell.ExpandEnvironmentStrings(iconPath) + objShortcut.Description = name + objShortcut.Save +End Sub + +CreateShortcut "openbb-cli", "C:\Windows\System32\cmd.exe", prefixPath & "\assets\openbb_icon.ico" +CreateShortcut "openbb-api", "C:\Windows\System32\cmd.exe", prefixPath & "\assets\openbb_icon.ico" +CreateShortcut "openbb-notebook", "C:\Windows\System32\cmd.exe", prefixPath & "\assets\openbb_icon.ico" +CreateShortcut "openbb-ipython", "C:\Windows\System32\cmd.exe", prefixPath & "\assets\openbb_icon.ico" +CreateShortcut "Update", "C:\Windows\System32\cmd.exe", prefixPath & "\assets\openbb_icon.ico" +CreateShortcut "CMD", "C:\Windows\System32\cmd.exe", prefixPath & "\assets\openbb_icon.ico" +CreateShortcut "Environments", prefixPath & "\envs", prefixPath & "\assets\openbb_icon.ico" +CreateShortcut "Settings", userProfilePath & "\.openbb_platform", prefixPath & "\assets\openbb_icon.ico" +CreateShortcut "OpenBBUserData", userProfilePath & "\OpenBBUserData", prefixPath & "\assets\openbb_icon.ico" +CreateShortcut "Uninstall", prefixPath & "\Uninstall-OpenBB.exe", prefixPath & "\assets\openbb_icon.ico" + +Set objShortcut = objShell.CreateShortcut(shortcutFolder & "\openbb-notebook.lnk") +objShortcut.Arguments = "/k PATH " & prefixPath & ";" & prefixPath & "\Scripts;" & prefixPath & "\Library\bin;%PATH% && activate " & prefixPath & "\envs\obb && cd " & shortcutFolder & " && jupyter-notebook && exit" +objShortcut.WorkingDirectory = shortcutFolder +objShortcut.Save + +Set objShortcut = objShell.CreateShortcut(shortcutFolder & "\openbb-ipython.lnk") +objShortcut.Arguments = "/k PATH " & prefixPath & ";" & prefixPath & "\Scripts;" & prefixPath & "\Library\bin;%PATH% && activate " & prefixPath & "\envs\obb && ipython -c ""from openbb import obb;obb"" -i" +objShortcut.WorkingDirectory = prefixPath +objShortcut.Save + +Set objShortcut = objShell.CreateShortcut(shortcutFolder & "\openbb-api.lnk") +objShortcut.Arguments = "/k PATH " & prefixPath & ";" & prefixPath & "\Scripts;" & prefixPath & "\Library\bin;%PATH% && activate " & prefixPath & "\envs\obb && call openbb-api --login && exit" +objShortcut.WorkingDirectory = prefixPath +objShortcut.Save + + +Set objShortcut = objShell.CreateShortcut(shortcutFolder & "\Update.lnk") +objShortcut.Arguments = "/k PATH " & prefixPath & ";" & prefixPath & "\Scripts;" & prefixPath & "\Library\bin;%PATH% && activate " & prefixPath & "\envs\obb && call openbb-update && exit" +objShortcut.WorkingDirectory = prefixPath +objShortcut.Save + +Set objShortcut = objShell.CreateShortcut(shortcutFolder & "\CMD.lnk") +objShortcut.Arguments = "/k PATH " & prefixPath & ";" & prefixPath & "\Scripts;" & prefixPath & "\Library\bin;%PATH% && activate base && echo Conda base environment is active. Use this shell to create new environments. && echo To activate the OpenBB environment, run 'conda activate obb'." +objShortcut.WorkingDirectory = shortcutFolder +objShortcut.Save + +Set objShortcut = objShell.CreateShortcut(shortcutFolder & "\openbb-cli.lnk") +objShortcut.Arguments = "/k PATH " & prefixPath & ";" & prefixPath & "\Scripts;" & prefixPath & "\Library\bin;%PATH% && activate " & prefixPath & "\envs\obb && call openbb && exit" +objShortcut.WorkingDirectory = prefixPath +objShortcut.Save \ No newline at end of file diff --git a/build/conda/installer/assets/custom_conclusion.nsi b/build/conda/installer/assets/custom_conclusion.nsi new file mode 100644 index 0000000000000000000000000000000000000000..ec0839a44d1f3950116a92073440db46705318bc --- /dev/null +++ b/build/conda/installer/assets/custom_conclusion.nsi @@ -0,0 +1,86 @@ + + +Page Custom muiExtraPages_Create + +!include "FileFunc.nsh" + +var IntroText +var InstallationLink +var ExampleImg +var ExampleImgCtl +var PARENTDIR + +Function muiExtraPages_Create + Push $0 + + !insertmacro MUI_HEADER_TEXT_PAGE \ + "${PRODUCT_NAME}" \ + "Installation Successfully Complete" + + ${GetParent} "$INSTDIR" $PARENTDIR + + nsDialogs::Create /NOUNLOAD 1018 + ${NSD_CreateLabel} 10u 10u 280u 40u "Click the link below to open the installation folder:" + Pop $IntroText + + ${NSD_CreateLink} 10u 55u 200u 10u $PARENTDIR + Pop $InstallationLink + ${NSD_OnClick} $InstallationLink LaunchLinkOne + + nsDialogs::CreateControl STATIC ${WS_VISIBLE}|${WS_CHILD}|${WS_CLIPSIBLINGS}|${SS_BITMAP}|${SS_REALSIZECONTROL} 0 10u 90u 280u 40u "" + Pop $ExampleImgCtl + StrCpy $0 $PLUGINSDIR\openbb_win.png + System::Call 'user32::LoadImage(i 0, t r0, i ${IMAGE_BITMAP}, i 0, i 0, i ${LR_LOADFROMFILE}|${LR_LOADTRANSPARENT}|${LR_LOADMAP3DCOLORS}) i.s' + Pop $ExampleImg + SendMessage $ExampleImgCtl ${STM_SETIMAGE} ${IMAGE_BITMAP} $ExampleImg + + nsDialogs::Show + + System::Call 'gdi32:DeleteObject(i $ExampleImg)' + + Pop $0 +FunctionEnd + +!define MUI_FINISHPAGE_TEXT "Select a resource to open.$\r$\n$\r$\n" +!define MUI_FINISHPAGE_RUN +!define MUI_FINISHPAGE_RUN_TEXT "OpenBB Platform Documentation" +!define MUI_FINISHPAGE_RUN_FUNCTION "LaunchLinkTwo" +!define MUI_PAGE_CUSTOMFUNCTION_SHOW MyFinishShow +!define MUI_PAGE_CUSTOMFUNCTION_LEAVE MyFinishLeave + +var CheckboxLinkThree +var CheckboxLinkFour + +Function LaunchLinkOne + ExecShell "open" "$PARENTDIR" +FunctionEnd + +Function LaunchLinkTwo + ExecShell "open" "https://docs.openbb.co/platform" +FunctionEnd + +Function MyFinishShow + ${NSD_CreateCheckbox} 120u 110u 100% 10u "OpenBB CLI Documentation" + Pop $CheckboxLinkThree + ${NSD_Check} $CheckboxLinkThree + SetCtlColors $CheckboxLinkThree "" "ffffff" + + ${NSD_CreateCheckbox} 120u 130u 100% 10u "OpenBB Pro Documentation" + Pop $CheckboxLinkFour + ${NSD_Check} $CheckboxLinkFour + SetCtlColors $CheckboxLinkFour "" "ffffff" +FunctionEnd + +Function MyFinishLeave + ${NSD_GetState} $CheckboxLinkThree $0 + ${If} $0 <> 0 + ExecShell "open" "https://docs.openbb.co/cli" + ${EndIf} + + ${NSD_GetState} $CheckboxLinkFour $0 + ${If} $0 <> 0 + ExecShell "open" "https://docs.openbb.co/pro" + ${EndIf} +FunctionEnd + +!insertmacro MUI_PAGE_FINISH \ No newline at end of file diff --git a/build/conda/installer/assets/custom_welcome.nsi b/build/conda/installer/assets/custom_welcome.nsi new file mode 100644 index 0000000000000000000000000000000000000000..461082fac36e46b378870b497e9aa2c063d8a821 --- /dev/null +++ b/build/conda/installer/assets/custom_welcome.nsi @@ -0,0 +1,41 @@ +# Below is an example of creating multiple pages after the welcome page of the installer. +# +# This file contains code that is inserted where the @CUSTOM_WELCOME_FILE@ is located +# in the main.nsi.tmpl. The main mechanism for extra pages occurs with the +# "Page Custom muiExtraPagesAfterWelcome_Create" line, which +# references the function "muiExtraPagesAfterWelcome_Create" for page creation. + +!define MUI_PAGE_CUSTOMFUNCTION_PRE SkipPageIfUACInnerInstance +!insertmacro MUI_PAGE_WELCOME + +Page Custom muiExtraPagesAfterWelcome_Create + +var IntroAfterWelcomeText +var InstallationAfterWelcomeLink +var ExampleAfterWelcomeImg +var ExampleImgAfterWelcomeCtl + +Function muiExtraPagesAfterWelcome_Create + Push $0 + + !insertmacro MUI_HEADER_TEXT_PAGE \ + "${PRODUCT_NAME}" \ + "Welcome to OpenBB Platform Installer" + + nsDialogs::Create /NOUNLOAD 1018 + ${NSD_CreateLabel} 10u 10u 280u 120u "Welcome to the OpenBB Platform Installer.$\r$\n$\r$\nThis application will install the latest version of the OpenBB Platform on your computer as a self-contained, Python 3.12, Conda environment.$\r$\n$\r$\nIn order to install you need access to the Internet.$\r$\n$\r$\nInstallation requires between 1-2 GB of storage space, with a minimum of 4GB RAM.$\r$\n$\r$\nWhen a non-default installation path is chosen, it requires a depth of two - i.e, User/MyUserAccount/OpenBB/conda, where OpenBB is the target folder, and conda is the name of the folder where Conda and the installed environments live. The path, including username, should not contain any spaces." + Pop $IntroAfterWelcomeText + + nsDialogs::CreateControl STATIC ${WS_VISIBLE}|${WS_CHILD}|${WS_CLIPSIBLINGS}|${SS_BITMAP}|${SS_REALSIZECONTROL} 0 10u 90u 280u 40u "" + Pop $ExampleImgAfterWelcomeCtl + StrCpy $0 $PLUGINSDIR\openbb_win.png + System::Call 'user32::LoadImage(i 0, t r0, i ${IMAGE_BITMAP}, i 0, i 0, i ${LR_LOADFROMFILE}|${LR_LOADTRANSPARENT}|${LR_LOADMAP3DCOLORS}) i.s' + Pop $ExampleAfterWelcomeImg + SendMessage $ExampleImgAfterWelcomeCtl ${STM_SETIMAGE} ${IMAGE_BITMAP} $ExampleAfterWelcomeImg + + nsDialogs::Show + + System::Call 'gdi32:DeleteObject(i $ExampleAfterWelcomeImg)' + + Pop $0 +FunctionEnd \ No newline at end of file diff --git a/build/conda/installer/assets/dmg_volume.icns b/build/conda/installer/assets/dmg_volume.icns new file mode 100644 index 0000000000000000000000000000000000000000..f5ff8ce96fdf51b603fb2128057b01a185c12a04 --- /dev/null +++ b/build/conda/installer/assets/dmg_volume.icns @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0e103259cce429d278e0dc98359e215d4cabfc7911fa8feffa42e5c16dbbb0d6 +size 674218 diff --git a/build/conda/installer/assets/examples/README.md b/build/conda/installer/assets/examples/README.md new file mode 100644 index 0000000000000000000000000000000000000000..96ddb0c9cde14eeec819d25c9e88925edc4b8d53 --- /dev/null +++ b/build/conda/installer/assets/examples/README.md @@ -0,0 +1,40 @@ +# Example Extension Templates + +The extensions in this folder represent starting points for creating your own OpenBB extensions. The types of extensions that can be created are: + +- Router + - Create a new router path and define the functions for the app. +- Provider + - Add a new data provider source. +- OBBject + - Extend the response object returned by every command. + +## Installation + +### All Examples + +To install all example extensions, activate the environment, then run: + +```sh +python install_examples.py +``` + +### Individual Example + +To install an individual extension to the existing OpenBB environment, activate it, then navigate into the folder of the desired extension and enter: + +```sh +poetry install --only-root +``` + +Then, rebuild the OpenBB Python interface with: + +```sh +openbb-build +``` + +The new extension(s) will be available by importing the OpenBB package. + +```python +from openbb import obb +``` diff --git a/build/conda/installer/assets/examples/empty_obbject/README.md b/build/conda/installer/assets/examples/empty_obbject/README.md new file mode 100644 index 0000000000000000000000000000000000000000..d5f24806ed72dc5e0efd8a25b422ddbd93c4b233 --- /dev/null +++ b/build/conda/installer/assets/examples/empty_obbject/README.md @@ -0,0 +1,9 @@ +# Empty OBBject Extension + +This is an empty OpenBB Platform OBBJECT (Response Object) Extension. + +Install this extension locally with: + +```console +poetry install --only-root +``` \ No newline at end of file diff --git a/build/conda/installer/assets/examples/empty_obbject/empty_obbject/__init__.py b/build/conda/installer/assets/examples/empty_obbject/empty_obbject/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..4e8d88a52e06ebe057d87723f23e7f8c5c788658 --- /dev/null +++ b/build/conda/installer/assets/examples/empty_obbject/empty_obbject/__init__.py @@ -0,0 +1,30 @@ +"""Empty OBBject extension.""" + +import warnings + +from openbb_core.app.model.extension import Extension +from openbb_core.app.model.obbject import OBBject + +warnings.filterwarnings( + "ignore", lineno=0 +) # This suppresses a warning you might see with IPython and OBBject Extensions on import and initialize. + +ext = Extension(name="empty") + +# OBBject Accessors are used to extend the functionality of the OBBject class. +# The name given to the Extension creates a new namespace in every output object of the Router. +# This is useful for formatting/processing the output of the function calls, where universal application is desired. + + +@ext.obbject_accessor +class Empty: + """An Empty OBBject extension.""" + + def __init__(self, obbject): + """Creates an instance of the Empty OBBject extension.""" + self._obbject: OBBject = obbject + + @staticmethod + def hello(): + """Print a greeting message.""" + print("Hello from the Empty OBBject extension!") # noqa: T201 diff --git a/build/conda/installer/assets/examples/empty_obbject/pyproject.toml b/build/conda/installer/assets/examples/empty_obbject/pyproject.toml new file mode 100644 index 0000000000000000000000000000000000000000..7f569f23a4e2cfc38736ba8990f02c0d9cd52688 --- /dev/null +++ b/build/conda/installer/assets/examples/empty_obbject/pyproject.toml @@ -0,0 +1,18 @@ +[tool.poetry] +name = "empty-obbject" +version = "0.0.1" +description = "An empty OBBject extension" +authors = ["OpenBB Team "] +readme = "README.md" +packages = [{ include = "empty_obbject" }] + +[tool.poetry.dependencies] +python = "^3.9.21,<3.13" +openbb-core = "^1.4.6" + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" + +[tool.poetry.plugins."openbb_obbject_extension"] +empty = "empty_obbject:ext" diff --git a/build/conda/installer/assets/examples/empty_provider/README.md b/build/conda/installer/assets/examples/empty_provider/README.md new file mode 100644 index 0000000000000000000000000000000000000000..1c65726275012db880fd8c115b4fd98fc37854d1 --- /dev/null +++ b/build/conda/installer/assets/examples/empty_provider/README.md @@ -0,0 +1,9 @@ +# Empty Provider Extension + +This is an empty OpenBB Platform Provider Extension. + +Install this extension locally with: + +```console +poetry install --only-root +``` \ No newline at end of file diff --git a/build/conda/installer/assets/examples/empty_provider/empty_provider/__init__.py b/build/conda/installer/assets/examples/empty_provider/empty_provider/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..b1010176fea19d162e97806f4618d640f71069f2 --- /dev/null +++ b/build/conda/installer/assets/examples/empty_provider/empty_provider/__init__.py @@ -0,0 +1,21 @@ +"""Empty Provider Module.""" + +# Import the fetchers from each model. +from openbb_core.provider.abstract.provider import Provider + +from empty_provider.models.empty_model import EmptyFetcher + +empty_provider = Provider( + name="empty", + website="http://empty.io", + description="""The empty provider is a supplier of promises.""", + # credentials=["api_key"], # Credentials added here are mapped to `user_settings.json` in the `credentials` key. + fetcher_dict={ + "Empty": EmptyFetcher # The key is the name of the model defined in the @router decorator. + }, +) + +# Every provider follows this same pattern, so it is possible to import the fetchers from other providers +# and map them to the fetcher_dict above. +# from openbb_yfinance import yfinance_provider +# yfinance_fetchers = yfinance_provider.fetcher_dict.copy() diff --git a/build/conda/installer/assets/examples/empty_provider/empty_provider/models/__init__.py b/build/conda/installer/assets/examples/empty_provider/empty_provider/models/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..b62c0791abc626042a30f8ade10354cce5131415 --- /dev/null +++ b/build/conda/installer/assets/examples/empty_provider/empty_provider/models/__init__.py @@ -0,0 +1 @@ +"""Empty Provider Models.""" diff --git a/build/conda/installer/assets/examples/empty_provider/empty_provider/models/empty_model.py b/build/conda/installer/assets/examples/empty_provider/empty_provider/models/empty_model.py new file mode 100644 index 0000000000000000000000000000000000000000..d8b02760c5fe9d1e8922cce66f00adfdbbeac7ef --- /dev/null +++ b/build/conda/installer/assets/examples/empty_provider/empty_provider/models/empty_model.py @@ -0,0 +1,93 @@ +"""Empty Fetcher Model. This model is used in conjunction with the 'empty_router' extension.""" + +# pylint: disable=unused-import +# flake8: noqa: F401 + +from datetime import ( + date as dateType, + datetime, +) +from typing import Any, Dict, Optional + +from openbb_core.provider.abstract.data import Data +from openbb_core.provider.abstract.fetcher import Fetcher +from openbb_core.provider.abstract.query_params import QueryParams +from pydantic import Field + + +class EmptyQueryParams(QueryParams): + """Empty Query Params""" + + some_param: Optional[str] = Field( + default=None, + description="Some param", + ) + + +class EmptyData(Data): + """Empty Data""" + + date: Optional[dateType] = Field( + default=None, + description="Date of the data.", + ) + title: Optional[str] = Field( + default=None, + description="Title of the data.", + ) + + +class EmptyFetcher( + Fetcher[ + EmptyQueryParams, + EmptyData, # Change the Typing when returning a list of models - i.e, records. + ] +): + """Empty Fetcher.""" + + @staticmethod + def transform_query(params: Dict[str, Any]) -> EmptyQueryParams: + """Transform query params.""" + transformed_params = params.copy() + # if transformed_params.get("some_param"): + # do something + # + # This is where you can set default values for query parameters. + # Essentially, `@model_validate(mode='before')`. + return EmptyQueryParams(**transformed_params) + + @staticmethod + async def aextract_data( + query: EmptyQueryParams, + credentials: Optional[Dict[str, str]], + **kwargs: Any, + ) -> Dict: # Typing here should match the 'data' input of 'transform_data'. + """Extract data.""" + # pylint: disable=import-outside-toplevel + # from openbb_core.provider.utils.helpers import ( + # make_request, + # amake_request, + # amake_requests, + # get_querystring, + # ) Use these to make HTTP requests. + + # We import here so that items are imported on execution, not on initialization. + # Critical for modules that introduce a heavy load on the system. + # Generally, any module required for data retrieval and parsing should be 'lazy' imported. + # This is to ensure that the module is only imported when needed. + + print(query.some_param) # noqa: T201 + results = { + "date": datetime.now().date(), + "title": "Hello from the Empty Provider extension!", + } + return results + + @staticmethod + def transform_data( + query: EmptyQueryParams, + data: Dict, # Typing here matches the output of '(a)extract_data'. + **kwargs: Any, + ) -> EmptyData: # Typing here matches the Fetcher's definition. + """Transform data.""" + return EmptyData.model_validate(data) diff --git a/build/conda/installer/assets/examples/empty_provider/empty_provider/utils/__init__.py b/build/conda/installer/assets/examples/empty_provider/empty_provider/utils/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..da3e91ec2bdf2ac5de1934a642a6b2ec8ad86023 --- /dev/null +++ b/build/conda/installer/assets/examples/empty_provider/empty_provider/utils/__init__.py @@ -0,0 +1 @@ +"""Utilities and Helpers.""" diff --git a/build/conda/installer/assets/examples/empty_provider/pyproject.toml b/build/conda/installer/assets/examples/empty_provider/pyproject.toml new file mode 100644 index 0000000000000000000000000000000000000000..512d34f8b6b9673dc6276029897ed86abc91baef --- /dev/null +++ b/build/conda/installer/assets/examples/empty_provider/pyproject.toml @@ -0,0 +1,18 @@ +[tool.poetry] +name = "empty-provider" +version = "0.0.1" +description = "Empty provider extension for OpenBB" +authors = ["OpenBB Team "] +readme = "README.md" +packages = [{ include = "empty_provider" }] + +[tool.poetry.dependencies] +python = "^3.9.21,<3.13" +openbb-core = "^1.4.6" + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" + +[tool.poetry.plugins."openbb_provider_extension"] +empty = "empty_provider:empty_provider" diff --git a/build/conda/installer/assets/examples/empty_router/README.md b/build/conda/installer/assets/examples/empty_router/README.md new file mode 100644 index 0000000000000000000000000000000000000000..e10523ea58050843798382fb994fb38db4d3dd2a --- /dev/null +++ b/build/conda/installer/assets/examples/empty_router/README.md @@ -0,0 +1,9 @@ +# Empty Router Extension + +This is an empty OpenBB Platform Router Extension. + +Install this extension locally with: + +```console +poetry install --only-root +``` \ No newline at end of file diff --git a/build/conda/installer/assets/examples/empty_router/empty_router/__init__.py b/build/conda/installer/assets/examples/empty_router/empty_router/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..100f486d1016e62dbc426ae0906356ed507410a5 --- /dev/null +++ b/build/conda/installer/assets/examples/empty_router/empty_router/__init__.py @@ -0,0 +1 @@ +"""An Empty OpenBB Router extension.""" diff --git a/build/conda/installer/assets/examples/empty_router/empty_router/empty_router.py b/build/conda/installer/assets/examples/empty_router/empty_router/empty_router.py new file mode 100644 index 0000000000000000000000000000000000000000..142416f04e6d6a9afbd4a8c974082678e40a98d0 --- /dev/null +++ b/build/conda/installer/assets/examples/empty_router/empty_router/empty_router.py @@ -0,0 +1,69 @@ +"""Empty Router Extenision for OpenBB Platform.""" + +from datetime import datetime + +from openbb_core.app.model.command_context import CommandContext +from openbb_core.app.model.example import APIEx, PythonEx +from openbb_core.app.model.obbject import OBBject +from openbb_core.app.provider_interface import ( + ExtraParams, + ProviderChoices, + StandardParams, +) +from openbb_core.app.query import Query +from openbb_core.app.router import Router +from openbb_core.provider.abstract.data import Data + +router = Router(prefix="", description="An Empty OpenBB Router Extension.") + +# The first function call will take longer than the rest, as modules are loaded on the first call. + +# Note that all routers must return an instance of `OBBject`, where the output is the `results` attribute. + + +# This is a standard router "get" command. +@router.command( + methods=["GET"], + examples=[ + PythonEx( + description="Say Hello.", + code=[ + "result = obb.empty.hello()", + ], + ), + ], +) +async def hello() -> ( + OBBject[dict] +): # The output of every router command must be an instance of `OBBject`. + """OpenBB Hello World.""" + return OBBject( + results={ + datetime.now().strftime( + "%Y-%m-%d" + ): "Hello from the Empty Router extension!" + } + ) + + +# This uses the Provider Interface to call the empty provider fetcher. +@router.command( + model="Empty", + examples=[ + APIEx(parameters={"provider": "empty"}), + PythonEx( + description="Say Hello.", + code=[ + "result = obb.empty.empty_function()", + ], + ), + ], +) +async def empty_function( + cc: CommandContext, + provider_choices: ProviderChoices, + standard_params: StandardParams, + extra_params: ExtraParams, +) -> OBBject[Data]: + """An empty function using the Provider Interface.""" + return await OBBject.from_query(Query(**locals())) diff --git a/build/conda/installer/assets/examples/empty_router/empty_router/empty_views.py b/build/conda/installer/assets/examples/empty_router/empty_router/empty_views.py new file mode 100644 index 0000000000000000000000000000000000000000..aa9fa999b7d70473883a5b78771855974ea08db5 --- /dev/null +++ b/build/conda/installer/assets/examples/empty_router/empty_router/empty_views.py @@ -0,0 +1,29 @@ +"""Views for the Empty Extension.""" + +# pylint: disable=unused-import +# flake8: noqa: F401 + +from typing import TYPE_CHECKING, Any, Dict, Tuple + +if TYPE_CHECKING: + from openbb_charting.core.openbb_figure import OpenBBFigure + +# If `openbb-charting` was installed, this will be used to create a chart. +# Process the data by accessing, "kwargs["obbject_item"]", the function results. +# The return is a Tuple of the OpenBBFigure and a Dict of the data, so it can be +# returned to the Fast API endpoint. Use `fig.to_plotly_json()` to convert the +# OpenBBFigure to a JSON serializable object. + + +class EmptyViews: + """Empty Views.""" + + # @staticmethod + # def empty_hello( # noqa: PLR0912 + # **kwargs, + # ) -> Tuple["OpenBBFigure", Dict[str, Any]]: + # """Get Derivatives Price Historical Chart.""" + # pylint: disable=import-outside-toplevel + # from openbb_charting.charts.price_historical import price_historical + + # return price_historical(**kwargs) diff --git a/build/conda/installer/assets/examples/empty_router/pyproject.toml b/build/conda/installer/assets/examples/empty_router/pyproject.toml new file mode 100644 index 0000000000000000000000000000000000000000..afd594e1d56e754407bb4c002bc4374f2a9f8bb9 --- /dev/null +++ b/build/conda/installer/assets/examples/empty_router/pyproject.toml @@ -0,0 +1,18 @@ +[tool.poetry] +name = "empty-router" +version = "0.0.1" +description = "An empty OpenBB Router extension" +authors = ["OpenBB Team "] +readme = "README.md" +packages = [{ include = "empty_router" }] + +[tool.poetry.dependencies] +python = "^3.9.21,<3.13" +openbb-core = "^1.4.6" + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" + +[tool.poetry.plugins."openbb_core_extension"] +empty = "empty_router.empty_router:router" diff --git a/build/conda/installer/assets/examples/install_examples.py b/build/conda/installer/assets/examples/install_examples.py new file mode 100644 index 0000000000000000000000000000000000000000..8a64b94c875c802097d644c88a7d40b178dadb47 --- /dev/null +++ b/build/conda/installer/assets/examples/install_examples.py @@ -0,0 +1,48 @@ +"""Script to install the example extensions in develop mode to the current Python environment.""" + + +def main(): + """Run the setup script.""" + # pylint: disable=import-outside-toplevel + import glob + import os + import subprocess + from pathlib import Path + + try: + import openbb # noqa: F401 # pylint: disable=unused-import + except ImportError: + subprocess.check_call("openbb-build", shell=True) # noqa: S602, S607 + + base_dir = Path(__file__).parent + + directories = [ + os.path.join(base_dir, d) + for d in os.listdir(base_dir) + if os.path.isdir(os.path.join(base_dir, d)) + and glob.glob(os.path.join(base_dir, d, "*.toml")) + ] + + for directory in directories: + subprocess.check_call( + [ # noqa: S603 + os.sys.executable, + "-m", + "poetry", + "install", + "-C", + directory, + "--only-root", + ] + ) + + subprocess.check_call("openbb-build", shell=True) # noqa: S602, S607 + + print( # noqa: T201 + "\nExample extensions have been installed and are ready-to-use." + "\nTo connect the examples to OpenBB Pro and edit the code live, run: openbb-api --reload\n" + ) + + +if __name__ == "__main__": + main() diff --git a/build/conda/installer/assets/examples/python_basics.ipynb b/build/conda/installer/assets/examples/python_basics.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..85ab032878d0b12c1f71ec5ecabc3947c426eb00 --- /dev/null +++ b/build/conda/installer/assets/examples/python_basics.ipynb @@ -0,0 +1,3848 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Getting The Python Basics Right\n", + "\n", + "Special thanks to PyQuantNews for donating this content. Subscribe [here](https://www.pyquantnews.com/) for free Python resources that will help you get started with Python for Quant Finance.\n", + "\n", + "## Code Comments\n", + "\n", + "A comment is a note made by a programmer in the source code of a program. Its purpose is to clarify the source code and make it easier for people to follow along with what is happening. Anything in a comment is generally ignored when the code is actually run, making comments useful for including explanations and reasoning as well as removing specific lines of code that you may be unsure about. Comments in Python are created by using the pound symbol (`# Insert Text Here`). Including a `#` in a line of code will comment out anything that follows it." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "# This is a comment\n", + "# These lines of code will not change any values\n", + "# Anything following the first # is not run as code" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You may hear text enclosed in triple quotes (`\"\"\" Insert Text Here \"\"\"`) referred to as multi-line comments, but this is not entirely accurate. This is a special type of `string` (a data type we will cover), called a `docstring`, used to explain the purpose of a function." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "' This is a special string '" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"\"\" This is a special string \"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "\u001b[0;31mInit signature:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m/\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mDocstring:\u001b[0m \n", + "str(object='') -> str\n", + "str(bytes_or_buffer[, encoding[, errors]]) -> str\n", + "\n", + "Create a new string object from the given object. If encoding or\n", + "errors is specified, then the object must expose a data buffer\n", + "that will be decoded using the given encoding and error handler.\n", + "Otherwise, returns the result of object.__str__() (if defined)\n", + "or repr(object).\n", + "encoding defaults to sys.getdefaultencoding().\n", + "errors defaults to 'strict'.\n", + "\u001b[0;31mType:\u001b[0m type\n", + "\u001b[0;31mSubclasses:\u001b[0m StrEnum, DeferredConfigString, FoldedCase, _rstr, _ScriptTarget, _ModuleTarget, LSString, include, Keys, InputMode, ..." + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "str??" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Make sure you read the comments within each code cell (if they are there). They will provide more real-time explanations of what is going on as you look at each line of code." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Python Objects - Basic Types & Variables\n", + "\n", + "Everything in Python is an **object** and every object in Python has a **type**. Some of the basic types include:\n", + "\n", + "- **`int`** (integer; a whole number with no decimal place)\n", + " - `10`\n", + " - `-3`\n", + "- **`float`** (float; a number that has a decimal place)\n", + " - `7.41`\n", + " - `-0.006`\n", + "- **`str`** (string; a sequence of characters enclosed in single quotes, double quotes, or triple quotes)\n", + " - `'this is a string using single quotes'`\n", + " - `\"this is a string using double quotes\"`\n", + " - `'''this is a triple quoted string using single quotes'''`\n", + " - `\"\"\"this is a triple quoted string using double quotes\"\"\"`\n", + "- **`bool`** (boolean; a binary value that is either true or false)\n", + " - `True`\n", + " - `False`\n", + "- **`NoneType`** (a special type representing the absence of a value)\n", + " - `None`\n", + "\n", + "In Python, a **variable** is a name you specify in your code that maps to a particular **object**, object **instance**, or value.\n", + "\n", + "By defining variables, we can refer to things by names that make sense to us. Names for variables can only contain letters, underscores (`_`), or numbers (no spaces, dashes, or other characters). Variable names must start with a letter or underscore.\n", + "\n", + "
" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Basic Operators\n", + "\n", + "In Python, there are different types of **operators** (special symbols) that operate on different values. Some of the basic operators include:\n", + "\n", + "- arithmetic operators\n", + " - **`+`** (addition)\n", + " - **`-`** (subtraction)\n", + " - **`*`** (multiplication)\n", + " - **`/`** (division)\n", + " - __`**`__ (exponent)\n", + "- assignment operators\n", + " - **`=`** (assign a value)\n", + " - **`+=`** (add and re-assign; increment)\n", + " - **`-=`** (subtract and re-assign; decrement)\n", + " - **`*=`** (multiply and re-assign)\n", + "- comparison operators (return either `True` or `False`)\n", + " - **`==`** (equal to)\n", + " - **`!=`** (not equal to)\n", + " - **`<`** (less than)\n", + " - **`<=`** (less than or equal to)\n", + " - **`>`** (greater than)\n", + " - **`>=`** (greater than or equal to)\n", + "\n", + "When multiple operators are used in a single expression, **operator precedence** determines which parts of the expression are evaluated in which order. Operators with higher precedence are evaluated first (like PEMDAS in math). Operators with the same precedence are evaluated from left to right.\n", + "\n", + "- `()` parentheses, for grouping\n", + "- `**` exponent\n", + "- `*`, `/` multiplication and division\n", + "- `+`, `-` addition and subtraction\n", + "- `==`, `!=`, `<`, `<=`, `>`, `>=` comparisons\n", + "\n", + "> See https://docs.python.org/3/reference/expressions.html#operator-precedence" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "# Assigning some numbers to different variables\n", + "num_1 = 10\n", + "num_2 = -3\n", + "num_3 = 7.41\n", + "num_4 = -0.6\n", + "num_5 = 7\n", + "num_6 = 3\n", + "num_7 = 11.11" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "10" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "num_1" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "7" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Addition\n", + "num_1 + num_2" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "-10.41" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Subtraction\n", + "num_2 - num_3" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "-4.446" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Multiplication\n", + "num_3 * num_4" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "-0.08571428571428572" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Division\n", + "num_4 / num_5" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "343" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Exponent\n", + "num_5**num_6" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "15.11" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Increment existing variable\n", + "num_7 += 4 # num_7 = num_7 + 4\n", + "num_7" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Decrement existing variable\n", + "num_6 -= 2\n", + "num_6" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "37.05" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Multiply & re-assign\n", + "num_3 *= 5\n", + "num_3" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "-101.14999999999999" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Assign the value of an expression to a variable\n", + "num_8 = num_1 + num_2 * num_3\n", + "num_8" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Are these two expressions equal to each other?\n", + "num_1 + num_2 == num_5" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Are these two expressions not equal to each other?\n", + "num_3 != num_4" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Is the first expression less than the second expression?\n", + "num_5 < num_6" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Is this expression True?\n", + "5 > 3 > 1" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Is this expression True?\n", + "5 > 3 < 4 == 3 + 1" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [], + "source": [ + "# Assign some strings to different variables\n", + "simple_string_1 = \"an example\"\n", + "simple_string_2 = \"oranges \"" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'an example of using the + operator'" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Addition\n", + "simple_string_1 + \" of using the + operator\"" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'an example'" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Notice that the string was not modified\n", + "simple_string_1" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'oranges oranges oranges oranges '" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Multiplication\n", + "simple_string_2 * 4" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'oranges '" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# This string wasn't modified either\n", + "simple_string_2" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Are these two expressions equal to each other?\n", + "simple_string_1 == simple_string_2" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Are these two expressions equal to each other?\n", + "simple_string_1 == \"an example\"" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'an example that re-assigned the original string'" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Add and re-assign\n", + "simple_string_1 += \" that re-assigned the original string\"\n", + "simple_string_1" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'oranges oranges oranges '" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Multiply and re-assign\n", + "simple_string_2 *= 3\n", + "simple_string_2" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [], + "source": [ + "# Note: Subtraction, division, and decrement operators do not apply to strings." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Basic Data Structures\n", + "\n", + "> Note: **mutable** objects can be modified after creation and **immutable** objects cannot.\n", + "\n", + "Containers are objects that can be used to group other objects together. The basic container types include:\n", + "\n", + "- **`str`** (string: immutable; indexed by integers; items are stored in the order they were added)\n", + "- **`list`** (list: mutable; indexed by integers; items are stored in the order they were added)\n", + " - `[3, 5, 6, 3, 'dog', 'cat', False]`\n", + "- **`tuple`** (tuple: immutable; indexed by integers; items are stored in the order they were added)\n", + " - `(3, 5, 6, 3, 'dog', 'cat', False)`\n", + "- **`set`** (set: mutable; not indexed at all; items are NOT stored in the order they were added; can only contain immutable objects; does NOT contain duplicate objects)\n", + " - `{3, 5, 6, 3, 'dog', 'cat', False}`\n", + "- **`dict`** (dictionary: mutable; key-value pairs are indexed by immutable keys; items are NOT stored in the order they were added)\n", + " - `{'name': 'Jane', 'age': 23, 'fav_foods': ['pizza', 'fruit', 'fish']}`\n", + "\n", + "When defining lists, tuples, or sets, use commas (,) to separate the individual items. When defining dicts, use a colon (:) to separate keys from values and commas (,) to separate the key-value pairs.\n", + "\n", + "Strings, lists, and tuples are all **sequence types** that can use the `+`, `*`, `+=`, and `*=` operators." + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [], + "source": [ + "# Assign some containers to different variables\n", + "list_1 = [3, 5, 6, 3, \"dog\", \"cat\", False]\n", + "tuple_1 = (3, 5, 6, 3, \"dog\", \"cat\", False)\n", + "set_1 = {3, 5, 6, 3, \"dog\", \"cat\", False}\n", + "set_2 = set((\"jane\", \"jaya\", \"jukes\", \"jason\", \"john\"))\n", + "dict_1 = {\"name\": \"Jane\", \"age\": 23, \"fav_foods\": [\"pizza\", \"fruit\", \"fish\"]}\n", + "dict_2 = {\"name\": \"Javier\", \"age\": 45, \"fav_foods\": [\"chicken\", \"veg\", \"candy\"]}" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[3, 5, 6, 3, 'dog', 'cat', False]" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Items in the list object are stored in the order they were added\n", + "list_1" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(3, 5, 6, 3, 'dog', 'cat', False)" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Items in the tuple object are stored in the order they were added\n", + "tuple_1" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{3, 5, 6, False, 'cat', 'dog'}" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Items in the set object are not stored in the order they were added\n", + "# Also, notice that the value 3 only appears once in this set object\n", + "set_1" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'name': 'Jane', 'age': 23, 'fav_foods': ['pizza', 'fruit', 'fish']}" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Items in the dict object are not stored in the order they were added\n", + "dict_1" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[3, 5, 6, 3, 'dog', 'cat', False, 5, 'grapes']" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Add and re-assign\n", + "list_1 += [5, \"grapes\"]\n", + "list_1" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(3, 5, 6, 3, 'dog', 'cat', False, 5, 'grapes')" + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Add and re-assign\n", + "tuple_1 += (5, \"grapes\")\n", + "tuple_1" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 2, 3, 4, 1, 2, 3, 4]" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Multiply\n", + "[1, 2, 3, 4] * 2" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4)" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Multiply\n", + "(1, 2, 3, 4) * 3" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Accessing Data In Containers\n", + "\n", + "For strings, lists, tuples, and dicts, we can use **subscript notation** (square brackets) to access data at an index.\n", + "\n", + "- strings, lists, and tuples are indexed by integers, **starting at 0** for first item\n", + " - these sequence types also support accesing a range of items, known as **slicing**\n", + " - use **negative indexing** to start at the back of the sequence\n", + "- dicts are indexed by their keys\n", + "\n", + "> Note: sets are not indexed, so we cannot use subscript notation to access data elements." + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[3, 5, 6, 3, 'dog', 'cat', False, 5, 'grapes']" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Remember what's in list_1\n", + "list_1" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Access the first item in a sequence\n", + "list_1[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(3, 5, 6, 3, 'dog', 'cat', False, 5, 'grapes')" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Remember what's in tuple_1\n", + "tuple_1" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'grapes'" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Access the last item in a sequence\n", + "tuple_1[-1]" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'an example that re-assigned the original string'" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Access a range of items in a sequence\n", + "simple_string_1" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'n'" + ] + }, + "execution_count": 44, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "simple_string_1[1]" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'an ex'" + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "simple_string_1[0:5]" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(5, 'grapes')" + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Access a range of items in a sequence\n", + "tuple_1[-2:]" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['dog', 'cat', False, 5, 'grapes']" + ] + }, + "execution_count": 47, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Access a range of items in a sequence\n", + "list_1[4:]" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'name': 'Jane', 'age': 23, 'fav_foods': ['pizza', 'fruit', 'fish']}" + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Rembember what's in dict_1\n", + "dict_1" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Jane'" + ] + }, + "execution_count": 49, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Access an item in a dictionary\n", + "# {'name': 'Jane', 'age': 23, 'fav_foods': ['pizza', 'fruit', 'fish']}\n", + "dict_1[\"name\"]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Python Built-In Functions & Callables\n", + "\n", + "A **function** is a Python object that you can \"call\" to **perform an action** or compute and **return another object**. You call a function by placing parentheses to the right of the function name. Some functions allow you to pass **arguments** inside the parentheses (separating multiple arguments with a comma). Internal to the function, these arguments are treated like variables.\n", + "\n", + "Python has several useful built-in functions to help you work with different objects and/or your environment. Here is a small sample of them:\n", + "\n", + "- **`type(obj)`** to determine the type of an object\n", + "- **`isinstance(val, obj)`** to determine if `val` is an `obj`\n", + "- **`len(container)`** to determine how many items are in a container\n", + "- **`callable(obj)`** to determine if an object is callable\n", + "- **`sorted(container)`** to return a new list from a container, with the items sorted\n", + "- **`sum(container)`** to compute the sum of a container of numbers\n", + "- **`min(container)`** to determine the smallest item in a container\n", + "- **`max(container)`** to determine the largest item in a container\n", + "- **`abs(number)`** to determine the absolute value of a number\n", + "- **`repr(obj)`** to return a string representation of an object\n", + "\n", + "> Complete list of built-in functions: https://docs.python.org/3/library/functions.html\n", + "\n", + "There are also different ways of defining your own functions and callable objects that we will explore later." + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "float" + ] + }, + "execution_count": 50, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Use the type() function to determine the type of an object\n", + "type(1.0)" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 51, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "price = \"1.11\"\n", + "isinstance(price, float)" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 52, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Use the len() function to determine how many items are in a container\n", + "len([1, 2, 3])" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "24" + ] + }, + "execution_count": 53, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Use the len() function to determine how many items are in a container\n", + "len(simple_string_2)" + ] + }, + { + "cell_type": "code", + "execution_count": 54, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 54, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Use the callable() function to determine if an object is callable\n", + "callable(\"a\")" + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 55, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Use the callable() function to determine if an object is callable\n", + "callable(dict_1)" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[-3, 1, 2, 3.6, 5, 7, 10]" + ] + }, + "execution_count": 56, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Use the sorted() function to return a new list from a container, with the items sorted\n", + "sorted([10, 1, 3.6, 7, 5, 2, -3])" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['a', 'j', 'n', 'o', 's']" + ] + }, + "execution_count": 57, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sorted(\"jason\")" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['California', 'Chicago', 'ants', 'cats', 'dogs', 'mice', 'zebras']" + ] + }, + "execution_count": 58, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Use the sorted() function to return a new list from a container, with the items sorted\n", + "# - notice that capitalized strings come first\n", + "sorted([\"dogs\", \"cats\", \"zebras\", \"Chicago\", \"California\", \"ants\", \"mice\"])" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "25.6" + ] + }, + "execution_count": 59, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Use the sum() function to compute the sum of a container of numbers\n", + "sum([10, 1, 3.6, 7, 5, 2, -3])" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "-3" + ] + }, + "execution_count": 60, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Use the min() function to determine the smallest item in a container\n", + "min([10, 1, 3.6, 7, 5, 2, -3])" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'a'" + ] + }, + "execution_count": 61, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Use the min() function to determine the smallest item in a container\n", + "min([\"g\", \"z\", \"a\", \"y\"])" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "10" + ] + }, + "execution_count": 62, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Use the max() function to determine the largest item in a container\n", + "max([10, 1, 3.6, 7, 5, 2, -3])" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'s'" + ] + }, + "execution_count": 63, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Use the max() function to determine the largest item in a container\n", + "max(\"gibberish\")" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "10" + ] + }, + "execution_count": 64, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Use the abs() function to determine the absolute value of a number\n", + "abs(10)" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "12" + ] + }, + "execution_count": 65, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Use the abs() function to determine the absolute value of a number\n", + "abs(-12)" + ] + }, + { + "cell_type": "code", + "execution_count": 66, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 66, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Use the repr() function to return a string representation of an object\n", + "isinstance(repr(list_1), str)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Python Object Attributes (Methods & Properties)\n", + "\n", + "Different types of objects in Python have different **attributes** that can be referred to by name (similar to a variable). To access an attribute of an object, use a dot (`.`) after the object, then specify the attribute (i.e. `obj.attribute`)\n", + "\n", + "When an attribute of an object is a callable, that attribute is called a **method**. It is the same as a function, only this function is bound to a particular object.\n", + "\n", + "When an attribute of an object is not a callable, that attribute is called a **property**. It is just a piece of data about the object, that is itself another object.\n", + "\n", + "The built-in `dir()` function can be used to return a list of an object's attributes.\n", + "\n", + "
" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Some Methods On `string` Objects\n", + "\n", + "- **`.capitalize()`** to return a capitalized version of the string (only first char uppercase)\n", + "- **`.upper()`** to return an uppercase version of the string (all chars uppercase)\n", + "- **`.lower()`** to return an lowercase version of the string (all chars lowercase)\n", + "- **`.count(substring)`** to return the number of occurences of the substring in the string\n", + "- **`.startswith(substring)`** to determine if the string starts with the substring\n", + "- **`.endswith(substring)`** to determine if the string ends with the substring\n", + "- **`.replace(old, new)`** to return a copy of the string with occurences of the \"old\" replaced by \"new\"" + ] + }, + { + "cell_type": "code", + "execution_count": 67, + "metadata": {}, + "outputs": [], + "source": [ + "# Assign a string to a variable\n", + "a_string = \"tHis is a sTriNg\"" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'This is a string'" + ] + }, + "execution_count": 68, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Return a capitalized version of the string\n", + "a_string.capitalize()" + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'THIS IS A STRING'" + ] + }, + "execution_count": 69, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Return an uppercase version of the string\n", + "a_string.upper()" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'this is a string'" + ] + }, + "execution_count": 70, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Return a lowercase version of the string\n", + "a_string.lower()" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'tHis is a sTriNg'" + ] + }, + "execution_count": 71, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Notice that the methods called have not actually modified the string\n", + "a_string" + ] + }, + { + "cell_type": "code", + "execution_count": 72, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 72, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Count number of occurences of a substring in the string\n", + "a_string.count(\"i\")" + ] + }, + { + "cell_type": "code", + "execution_count": 73, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 73, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Count number of occurences of a substring in the string after a certain position\n", + "a_string.count(\"i\", 7)" + ] + }, + { + "cell_type": "code", + "execution_count": 74, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 74, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Count number of occurences of a substring in the string\n", + "a_string.count(\"is\")" + ] + }, + { + "cell_type": "code", + "execution_count": 75, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 75, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Does the string start with 'this'?\n", + "a_string.startswith(\"this\")" + ] + }, + { + "cell_type": "code", + "execution_count": 76, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 76, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Does the lowercase string start with 'this'?\n", + "a_string.lower().startswith(\"this\")" + ] + }, + { + "cell_type": "code", + "execution_count": 77, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 77, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Does the string end with 'Ng'?\n", + "a_string.endswith(\"Ng\")" + ] + }, + { + "cell_type": "code", + "execution_count": 78, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'tHXYZ XYZ a sTriNg'" + ] + }, + "execution_count": 78, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Return a version of the string with a substring replaced with something else\n", + "a_string.replace(\"is\", \"XYZ\")" + ] + }, + { + "cell_type": "code", + "execution_count": 79, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'tH!s !s a sTr!Ng'" + ] + }, + "execution_count": 79, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Return a version of the string with a substring replaced with something else\n", + "a_string.replace(\"i\", \"!\")" + ] + }, + { + "cell_type": "code", + "execution_count": 80, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'tH!s !s a sTriNg'" + ] + }, + "execution_count": 80, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Return a version of the string with the first 2 occurences a substring replaced with something else\n", + "a_string.replace(\"i\", \"!\", 2)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "collapsed": true, + "jupyter": { + "outputs_hidden": true + } + }, + "source": [ + "## Some Methods On `list` Objects\n", + "\n", + "- **`.append(item)`** to add a single item to the list\n", + "- **`.extend([item1, item2, ...])`** to add multiple items to the list\n", + "- **`.remove(item)`** to remove a single item from the list\n", + "- **`.pop()`** to remove and return the item at the end of the list\n", + "- **`.pop(index)`** to remove and return an item at an index" + ] + }, + { + "cell_type": "code", + "execution_count": 81, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[3, 5, 6, 3, 'dog', 'cat', False, 5, 'grapes']" + ] + }, + "execution_count": 81, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Remember what's in list_1\n", + "list_1" + ] + }, + { + "cell_type": "code", + "execution_count": 82, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[3, 5, 6, 3, 'dog', 'cat', False, 5, 'grapes', 'basketball']" + ] + }, + "execution_count": 82, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# append a string to a list\n", + "list_1.append(\"basketball\")\n", + "list_1" + ] + }, + { + "cell_type": "code", + "execution_count": 83, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[3, 5, 6, 3, 'dog', 'cat', False, 5, 'grapes', 'basketball', 'baseball', 1]" + ] + }, + "execution_count": 83, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Add multiple items to a list\n", + "list_1.extend([\"baseball\", 1]) # equiv. list + list\n", + "list_1" + ] + }, + { + "cell_type": "code", + "execution_count": 84, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[3, 5, 6, 3, 'dog', False, 5, 'grapes', 'basketball', 'baseball', 1]" + ] + }, + "execution_count": 84, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Remove a sinle item from a list\n", + "list_1.remove(\"cat\")\n", + "list_1" + ] + }, + { + "cell_type": "code", + "execution_count": 85, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 85, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Remove the last item and return it\n", + "list_1.pop()" + ] + }, + { + "cell_type": "code", + "execution_count": 86, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[3, 5, 6, 3, 'dog', False, 5, 'grapes', 'basketball', 'baseball']" + ] + }, + "execution_count": 86, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list_1" + ] + }, + { + "cell_type": "code", + "execution_count": 87, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 87, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# remove an item at index 0 and return it\n", + "list_1.pop(0)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Some Methods On `set` Objects\n", + "\n", + "- **`.add(item)`** to add a single item to the set\n", + "- **`.update([item1, item2, ...])`** to add multiple items to the set\n", + "- **`.update(set_2, set3, ...)`** to add items from all provided sets to the set\n", + "- **`.remove(item)`** to remove a single item from the set\n", + "- **`.difference(set_2)`** to return items in the set that are not in another set\n", + "- **`.intersection(set_2)`** to return items in both sets\n", + "- **`.union(set_2)`** to return items that are in either set\n", + "- **`.symmetric_difference(set_2)`** to return items that are only in one set (not both)\n", + "- **`.issuperset(set_2)`** does the set contain everything in the other set?\n", + "- **`.issubset(set_2)`** is the set contained in the other set?" + ] + }, + { + "cell_type": "code", + "execution_count": 88, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'Jason', 'jason'}" + ] + }, + "execution_count": 88, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "set([\"Jason\", \"jason\", \"jason\"])" + ] + }, + { + "cell_type": "code", + "execution_count": 89, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{3, 5, 6, False, 'cat', 'dog', 'fuzz'}" + ] + }, + "execution_count": 89, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "set_1.add(\"fuzz\")\n", + "set_1" + ] + }, + { + "cell_type": "code", + "execution_count": 90, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{3, 5, 6, False, 'cat', 'coke', 'dog', 'fuzz', 'pepsi'}" + ] + }, + "execution_count": 90, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "set_1.update([\"coke\", \"pepsi\"])\n", + "set_1" + ] + }, + { + "cell_type": "code", + "execution_count": 91, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{3,\n", + " 5,\n", + " 6,\n", + " False,\n", + " 'cat',\n", + " 'coke',\n", + " 'dog',\n", + " 'fuzz',\n", + " 'jane',\n", + " 'jason',\n", + " 'jaya',\n", + " 'john',\n", + " 'jukes',\n", + " 'pepsi'}" + ] + }, + "execution_count": 91, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "set_1.update(set_2)\n", + "set_1" + ] + }, + { + "cell_type": "code", + "execution_count": 92, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{3,\n", + " 5,\n", + " 6,\n", + " False,\n", + " 'coke',\n", + " 'dog',\n", + " 'fuzz',\n", + " 'jane',\n", + " 'jason',\n", + " 'jaya',\n", + " 'john',\n", + " 'jukes',\n", + " 'pepsi'}" + ] + }, + "execution_count": 92, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "set_1.remove(\"cat\")\n", + "set_1" + ] + }, + { + "cell_type": "code", + "execution_count": 93, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{3, 5, 6, False, 'coke', 'dog', 'fuzz', 'pepsi'}" + ] + }, + "execution_count": 93, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "set_1.difference(set_2)" + ] + }, + { + "cell_type": "code", + "execution_count": 94, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'jane', 'jason', 'jaya', 'john', 'jukes'}" + ] + }, + "execution_count": 94, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "set_1.intersection(set_2)" + ] + }, + { + "cell_type": "code", + "execution_count": 95, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{3,\n", + " 5,\n", + " 6,\n", + " False,\n", + " 'coke',\n", + " 'dog',\n", + " 'fuzz',\n", + " 'jane',\n", + " 'jason',\n", + " 'jaya',\n", + " 'john',\n", + " 'jukes',\n", + " 'pepsi'}" + ] + }, + "execution_count": 95, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "set_1.union(set_2)" + ] + }, + { + "cell_type": "code", + "execution_count": 96, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 96, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "set_1.issuperset(set_2)" + ] + }, + { + "cell_type": "code", + "execution_count": 97, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 97, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "set_1.issubset(set_2)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Some Methods On `dict` Objects\n", + "\n", + "- **`.update([(key1, val1), (key2, val2), ...])`** to add multiple key-value pairs to the dict\n", + "- **`.update(dict_2)`** to add all keys and values from another dict to the dict\n", + "- **`.pop(key)`** to remove key and return its value from the dict (error if key not found)\n", + "- **`.pop(key, default_val)`** to remove key and return its value from the dict (or return default_val if key not found)\n", + "- **`.get(key)`** to return the value at a specified key in the dict (or None if key not found)\n", + "- **`.get(key, default_val)`** to return the value at a specified key in the dict (or default_val if key not found)\n", + "- **`.keys()`** to return a list of keys in the dict\n", + "- **`.values()`** to return a list of values in the dict\n", + "- **`.items()`** to return a list of key-value pairs (tuples) in the dict" + ] + }, + { + "cell_type": "code", + "execution_count": 98, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'name': 'Jane', 'age': 23, 'fav_foods': ['pizza', 'fruit', 'fish']}" + ] + }, + "execution_count": 98, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Remember what's in dict_1\n", + "dict_1" + ] + }, + { + "cell_type": "code", + "execution_count": 99, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'name': 'Jane',\n", + " 'age': 23,\n", + " 'fav_foods': ['pizza', 'fruit', 'fish'],\n", + " 'rain': True,\n", + " 'cars': 'a lot'}" + ] + }, + "execution_count": 99, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Update dict_1 with an iterable\n", + "dict_1.update([(\"rain\", True), (\"cars\", \"a lot\")])\n", + "dict_1" + ] + }, + { + "cell_type": "code", + "execution_count": 100, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'name': 'Javier',\n", + " 'age': 45,\n", + " 'fav_foods': ['chicken', 'veg', 'candy'],\n", + " 'rain': True,\n", + " 'cars': 'a lot'}" + ] + }, + "execution_count": 100, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Update dict_1 with another dict\n", + "dict_1.update(dict_2)\n", + "dict_1" + ] + }, + { + "cell_type": "code", + "execution_count": 101, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "45" + ] + }, + "execution_count": 101, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Remove the key and value at age\n", + "dict_1.pop(\"age\")" + ] + }, + { + "cell_type": "code", + "execution_count": 102, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'name': 'Javier',\n", + " 'fav_foods': ['chicken', 'veg', 'candy'],\n", + " 'rain': True,\n", + " 'cars': 'a lot'}" + ] + }, + "execution_count": 102, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Key and value are removed\n", + "dict_1" + ] + }, + { + "cell_type": "code", + "execution_count": 103, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "50" + ] + }, + "execution_count": 103, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Use a default value\n", + "dict_1.pop(\"age\", 50)" + ] + }, + { + "cell_type": "code", + "execution_count": 104, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'No car found'" + ] + }, + "execution_count": 104, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Use get to set a default\n", + "dict_1.get(\"car\", \"No car found\")" + ] + }, + { + "cell_type": "code", + "execution_count": 105, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "dict_keys(['name', 'fav_foods', 'rain', 'cars'])" + ] + }, + "execution_count": 105, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Get the keys of a dict as an iterable\n", + "dict_1.keys()" + ] + }, + { + "cell_type": "code", + "execution_count": 106, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "dict_values(['Javier', ['chicken', 'veg', 'candy'], True, 'a lot'])" + ] + }, + "execution_count": 106, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Get the values of a dict as an iterable\n", + "dict_1.values()" + ] + }, + { + "cell_type": "code", + "execution_count": 107, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "dict_items([('name', 'Javier'), ('fav_foods', ['chicken', 'veg', 'candy']), ('rain', True), ('cars', 'a lot')])" + ] + }, + "execution_count": 107, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Get the key-value pairs of a dict as an iterable\n", + "dict_1.items()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Positional Arguments & Keyword Arguments To Callables\n", + "\n", + "You can call a function/method in a number of different ways:\n", + "\n", + "- `func()`: Call `func` with no arguments\n", + "- `func(arg)`: Call `func` with one positional argument\n", + "- `func(arg1, arg2)`: Call `func` with two positional arguments\n", + "- `func(arg1, arg2, ..., argn)`: Call `func` with many positional arguments\n", + "- `func(kwarg=value)`: Call `func` with one keyword argument \n", + "- `func(kwarg1=value1, kwarg2=value2)`: Call `func` with two keyword arguments\n", + "- `func(kwarg1=value1, kwarg2=value2, ..., kwargn=valuen)`: Call `func` with many keyword arguments\n", + "- `func(arg1, arg2, kwarg1=value1, kwarg2=value2)`: Call `func` with positonal arguments and keyword arguments\n", + "- `obj.method()`: Same for `func`.. and every other `func` example\n", + "\n", + "When using **positional arguments**, you must provide them in the order that the function defined them (the function's **signature**).\n", + "\n", + "When using **keyword arguments**, you can provide the arguments you want, in any order you want, as long as you specify each argument's name.\n", + "\n", + "When using positional and keyword arguments, positional arguments must come first." + ] + }, + { + "cell_type": "code", + "execution_count": 108, + "metadata": {}, + "outputs": [], + "source": [ + "def func_1():\n", + " return 1 + 1" + ] + }, + { + "cell_type": "code", + "execution_count": 109, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 109, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "func_1()" + ] + }, + { + "cell_type": "code", + "execution_count": 110, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "25" + ] + }, + "execution_count": 110, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def func_2(x):\n", + " return x**2 # equiv. x^2\n", + "\n", + "\n", + "func_2(5)" + ] + }, + { + "cell_type": "code", + "execution_count": 111, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4.0" + ] + }, + "execution_count": 111, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def func_3(x, y):\n", + " return x / y\n", + "\n", + "\n", + "func_3(8, 2)" + ] + }, + { + "cell_type": "code", + "execution_count": 112, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'one': 1, 'two': 2, 'jason': 'banana'}\n" + ] + } + ], + "source": [ + "def func_4(**kwargs):\n", + " print(kwargs)\n", + "\n", + "\n", + "func_4(one=1, two=2, jason=\"banana\")" + ] + }, + { + "cell_type": "code", + "execution_count": 113, + "metadata": {}, + "outputs": [], + "source": [ + "def func_5(a, b, c, **kwargs):\n", + " pass\n", + "\n", + "\n", + "func_5(2, 3, c=5)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Python \"for loops\"\n", + "\n", + "It is easy to **iterate** over a collection of items using a **for loop**. The strings, lists, tuples, sets, and dictionaries we defined are all **iterable** containers.\n", + "\n", + "The for loop will go through the specified container, one item at a time, and provide a temporary variable for the current item. You can use this temporary variable like a normal variable." + ] + }, + { + "cell_type": "code", + "execution_count": 114, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5\n", + "6\n", + "3\n", + "dog\n", + "False\n", + "5\n", + "grapes\n", + "basketball\n", + "baseball\n" + ] + } + ], + "source": [ + "list_1\n", + "\n", + "for item in list_1:\n", + " print(item)" + ] + }, + { + "cell_type": "code", + "execution_count": 115, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n", + "5\n", + "6\n", + "3\n", + "dog\n", + "cat\n", + "False\n", + "5\n", + "grapes\n" + ] + } + ], + "source": [ + "for item in tuple_1:\n", + " print(item)" + ] + }, + { + "cell_type": "code", + "execution_count": 116, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n", + "3\n", + "5\n", + "6\n", + "john\n", + "jane\n", + "coke\n", + "jukes\n", + "jaya\n", + "jason\n", + "fuzz\n", + "pepsi\n", + "dog\n" + ] + } + ], + "source": [ + "for item in set_1:\n", + " print(item)" + ] + }, + { + "cell_type": "code", + "execution_count": 117, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Key:name -> Value:Javier\n", + "Key:fav_foods -> Value:['chicken', 'veg', 'candy']\n", + "Key:rain -> Value:True\n", + "Key:cars -> Value:a lot\n" + ] + } + ], + "source": [ + "for key, value in dict_1.items():\n", + " print(f\"Key:{key} -> Value:{value}\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Python \"if statements\" & \"while loops\"\n", + "\n", + "Conditional expressions can be used with these two **conditional statements**.\n", + "\n", + "The **if statement** allows you to test a condition and perform some actions if the condition evaluates to `True`. You can also provide `elif` and/or `else` clauses to an if statement to take alternative actions if the condition evaluates to `False`.\n", + "\n", + "The **while loop** will keep looping until its conditional expression evaluates to `False`.\n", + "\n", + "> Note: It is possible to \"loop forever\" when using a while loop with a conditional expression that never evaluates to `False`.\n", + ">\n", + "> Note: Since the **for loop** will iterate over a container of items until there are no more, there is no need to specify a \"stop looping\" condition." + ] + }, + { + "cell_type": "code", + "execution_count": 118, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Correct\n" + ] + } + ], + "source": [ + "if 1 < 2:\n", + " print(\"Correct\")" + ] + }, + { + "cell_type": "code", + "execution_count": 119, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 119, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "1 < 2" + ] + }, + { + "cell_type": "code", + "execution_count": 120, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Correct\n" + ] + } + ], + "source": [ + "if (1 < 2) and isinstance(\"jason\", str) and 1 and 12 < 20:\n", + " print(\"Correct\")" + ] + }, + { + "cell_type": "code", + "execution_count": 121, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Default\n" + ] + } + ], + "source": [ + "if 1 > 2:\n", + " print(\"Incorrect\")\n", + "elif 1 > 3:\n", + " print(\"Still incorrect\")\n", + "else:\n", + " print(\"Default\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## List Comprehensions" + ] + }, + { + "cell_type": "code", + "execution_count": 122, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 2, 3, 4, 5]" + ] + }, + "execution_count": 122, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Create a simple list\n", + "l = [1, 2, 3, 4, 5]\n", + "l" + ] + }, + { + "cell_type": "code", + "execution_count": 123, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 2, 3, 4, 5, 1, 2, 3, 4, 5]" + ] + }, + "execution_count": 123, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# This does not multiply each value by 2\n", + "l * 2" + ] + }, + { + "cell_type": "code", + "execution_count": 124, + "metadata": {}, + "outputs": [], + "source": [ + "# The long way to do it...\n", + "new_list = []\n", + "for item in l:\n", + " v = item * 2\n", + " new_list.append(v)" + ] + }, + { + "cell_type": "code", + "execution_count": 125, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[2, 4, 6, 8, 10]" + ] + }, + "execution_count": 125, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "new_list" + ] + }, + { + "cell_type": "code", + "execution_count": 126, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[2, 4, 6, 8, 10]" + ] + }, + "execution_count": 126, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Same result using a list comprehension\n", + "[item * 2 for item in l]" + ] + }, + { + "cell_type": "code", + "execution_count": 127, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[0.5, 1.0, 1.5, 2.0, 2.5]" + ] + }, + "execution_count": 127, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Another example\n", + "x = []\n", + "for i in [1, 2, 3, 4, 5]:\n", + " x.append(i / 2)\n", + "x" + ] + }, + { + "cell_type": "code", + "execution_count": 128, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[0.5, 1.0, 1.5, 2.0, 2.5]" + ] + }, + "execution_count": 128, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "[i / 2 for i in [1, 2, 3, 4, 5]]" + ] + }, + { + "cell_type": "code", + "execution_count": 129, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[int, int, int, str, bool, int, str, str, str]" + ] + }, + "execution_count": 129, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "[type(i) for i in list_1]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Importing Modules" + ] + }, + { + "cell_type": "code", + "execution_count": 130, + "metadata": {}, + "outputs": [], + "source": [ + "import math\n", + "import numpy" + ] + }, + { + "cell_type": "code", + "execution_count": 131, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3.0" + ] + }, + "execution_count": 131, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "math.sqrt(9)" + ] + }, + { + "cell_type": "code", + "execution_count": 132, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3.0" + ] + }, + "execution_count": 132, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "numpy.sqrt(9)" + ] + }, + { + "cell_type": "code", + "execution_count": 133, + "metadata": {}, + "outputs": [], + "source": [ + "import math as m" + ] + }, + { + "cell_type": "code", + "execution_count": 134, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3.0" + ] + }, + "execution_count": 134, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "m.sqrt(9)" + ] + }, + { + "cell_type": "code", + "execution_count": 135, + "metadata": {}, + "outputs": [], + "source": [ + "from math import sqrt\n", + "from numpy import sqrt" + ] + }, + { + "cell_type": "code", + "execution_count": 136, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3.0" + ] + }, + "execution_count": 136, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sqrt(9)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exceptions" + ] + }, + { + "cell_type": "code", + "execution_count": 137, + "metadata": {}, + "outputs": [ + { + "ename": "KeyError", + "evalue": "'food'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[137], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m dict3 \u001b[38;5;241m=\u001b[39m {\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mname\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mjason\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcar\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mnope\u001b[39m\u001b[38;5;124m\"\u001b[39m}\n\u001b[0;32m----> 2\u001b[0m \u001b[43mdict3\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mfood\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\n", + "\u001b[0;31mKeyError\u001b[0m: 'food'" + ] + } + ], + "source": [ + "dict3 = {\"name\": \"jason\", \"car\": \"nope\"}\n", + "dict3[\"food\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 138, + "metadata": {}, + "outputs": [ + { + "ename": "ZeroDivisionError", + "evalue": "division by zero", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mZeroDivisionError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[138], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;241;43m2\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m/\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\n", + "\u001b[0;31mZeroDivisionError\u001b[0m: division by zero" + ] + } + ], + "source": [ + "2 / 0" + ] + }, + { + "cell_type": "code", + "execution_count": 139, + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "set expected at most 1 argument, got 3", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[139], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;43mset\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m2\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m3\u001b[39;49m\u001b[43m)\u001b[49m\n", + "\u001b[0;31mTypeError\u001b[0m: set expected at most 1 argument, got 3" + ] + } + ], + "source": [ + "set(1, 2, 3)" + ] + }, + { + "cell_type": "code", + "execution_count": 140, + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'jason' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[140], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mjason\u001b[49m\n", + "\u001b[0;31mNameError\u001b[0m: name 'jason' is not defined" + ] + } + ], + "source": [ + "jason" + ] + }, + { + "cell_type": "code", + "execution_count": 141, + "metadata": {}, + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "invalid syntax (1125386000.py, line 1)", + "output_type": "error", + "traceback": [ + "\u001b[0;36m Cell \u001b[0;32mIn[141], line 1\u001b[0;36m\u001b[0m\n\u001b[0;31m 1 + 2:\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" + ] + } + ], + "source": [ + "1 + 2:" + ] + }, + { + "cell_type": "code", + "execution_count": 150, + "metadata": {}, + "outputs": [ + { + "ename": "Exception", + "evalue": "My own exception", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mException\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[150], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mMy own exception\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n", + "\u001b[0;31mException\u001b[0m: My own exception" + ] + } + ], + "source": [ + "raise Exception(\"My own exception\")" + ] + }, + { + "cell_type": "code", + "execution_count": 151, + "metadata": {}, + "outputs": [ + { + "ename": "AssertionError", + "evalue": "Pass a number >=0", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mAssertionError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[151], line 6\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m x \u001b[38;5;241m>\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;241m0\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mPass a number >=0\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m math\u001b[38;5;241m.\u001b[39msqrt(x)\n\u001b[0;32m----> 6\u001b[0m \u001b[43mfcn\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m-\u001b[39;49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m)\u001b[49m\n", + "Cell \u001b[0;32mIn[151], line 2\u001b[0m, in \u001b[0;36mfcn\u001b[0;34m(x)\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mfcn\u001b[39m(x):\n\u001b[0;32m----> 2\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m x \u001b[38;5;241m>\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;241m0\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mPass a number >=0\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m math\u001b[38;5;241m.\u001b[39msqrt(x)\n", + "\u001b[0;31mAssertionError\u001b[0m: Pass a number >=0" + ] + } + ], + "source": [ + "def fcn(x):\n", + " assert x >= 0, \"Pass a number >=0\"\n", + " return math.sqrt(x)\n", + "\n", + "\n", + "fcn(-1)" + ] + }, + { + "cell_type": "code", + "execution_count": 152, + "metadata": {}, + "outputs": [ + { + "ename": "ModuleNotFoundError", + "evalue": "No module named 'my_module'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[152], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mmy_module\u001b[39;00m\n", + "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'my_module'" + ] + } + ], + "source": [ + "import my_module" + ] + }, + { + "cell_type": "code", + "execution_count": 153, + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'calculate' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[153], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mcalculate\u001b[49m(\u001b[38;5;241m5\u001b[39m, \u001b[38;5;241m5\u001b[39m)\n", + "\u001b[0;31mNameError\u001b[0m: name 'calculate' is not defined" + ] + } + ], + "source": [ + "calculate(5, 5)" + ] + }, + { + "cell_type": "code", + "execution_count": 154, + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "math domain error", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[154], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mmath\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msqrt\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m-\u001b[39;49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m)\u001b[49m\n", + "\u001b[0;31mValueError\u001b[0m: math domain error" + ] + } + ], + "source": [ + "math.sqrt(-1)" + ] + }, + { + "cell_type": "code", + "execution_count": 155, + "metadata": {}, + "outputs": [ + { + "ename": "AttributeError", + "evalue": "module 'math' has no attribute 'my_func'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[155], line 3\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mmath\u001b[39;00m\n\u001b[0;32m----> 3\u001b[0m \u001b[43mmath\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmy_func\u001b[49m(\u001b[38;5;241m2\u001b[39m)\n", + "\u001b[0;31mAttributeError\u001b[0m: module 'math' has no attribute 'my_func'" + ] + } + ], + "source": [ + "import math\n", + "\n", + "math.my_func(2)" + ] + }, + { + "cell_type": "code", + "execution_count": 156, + "metadata": {}, + "outputs": [ + { + "ename": "AttributeError", + "evalue": "'str' object has no attribute 'my_func'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[156], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mjason\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmy_func\u001b[49m()\n", + "\u001b[0;31mAttributeError\u001b[0m: 'str' object has no attribute 'my_func'" + ] + } + ], + "source": [ + "\"jason\".my_func()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Classes: Creating Your Own Objects" + ] + }, + { + "cell_type": "code", + "execution_count": 157, + "metadata": {}, + "outputs": [], + "source": [ + "class JasonStrimpel:\n", + " pass\n", + "\n", + "\n", + "class ThisIsMyClass:\n", + " pass" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 158, + "metadata": {}, + "outputs": [], + "source": [ + "# Define a new class called `Thing` that is derived from the base Python object\n", + "class Car(object):\n", + " color = \"red\"" + ] + }, + { + "cell_type": "code", + "execution_count": 159, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "__main__.Car" + ] + }, + "execution_count": 159, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Create \"instances\" of our new classes\n", + "a = Car()\n", + "b = Car()\n", + "c = Car()\n", + "\n", + "type(c)" + ] + }, + { + "cell_type": "code", + "execution_count": 160, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'red'" + ] + }, + "execution_count": 160, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "c.color" + ] + }, + { + "cell_type": "code", + "execution_count": 161, + "metadata": {}, + "outputs": [], + "source": [ + "# Interact with a DictThing instance just as you would a normal dictionary\n", + "# Define a new class called `DictThing` that is derived from the `dict` type\n", + "class DictThing(dict):\n", + " my_property = 'I am a \"DictThing\"'" + ] + }, + { + "cell_type": "code", + "execution_count": 162, + "metadata": {}, + "outputs": [], + "source": [ + "d = DictThing()" + ] + }, + { + "cell_type": "code", + "execution_count": 163, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'name': 'Javier',\n", + " 'fav_foods': ['chicken', 'veg', 'candy'],\n", + " 'rain': True,\n", + " 'cars': 'a lot'}" + ] + }, + "execution_count": 163, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dict_1" + ] + }, + { + "cell_type": "code", + "execution_count": 164, + "metadata": {}, + "outputs": [ + { + "ename": "AttributeError", + "evalue": "'dict' object has no attribute 'my_property'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[164], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mdict_1\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmy_property\u001b[49m\n", + "\u001b[0;31mAttributeError\u001b[0m: 'dict' object has no attribute 'my_property'" + ] + } + ], + "source": [ + "dict_1.my_property" + ] + }, + { + "cell_type": "code", + "execution_count": 165, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'age': 13, 'fav_foods': ['pizza', 'sushi', 'pad thai', 'waffles'], 'fav_color': 'green'}\n" + ] + } + ], + "source": [ + "d.update(\n", + " {\n", + " \"age\": 13,\n", + " \"fav_foods\": [\"pizza\", \"sushi\", \"pad thai\", \"waffles\"],\n", + " \"fav_color\": \"green\",\n", + " }\n", + ")\n", + "print(d)" + ] + }, + { + "cell_type": "code", + "execution_count": 166, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "I am a \"DictThing\"\n" + ] + } + ], + "source": [ + "print(d.my_property)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Creating An Initializer Method For Classes" + ] + }, + { + "cell_type": "code", + "execution_count": 167, + "metadata": {}, + "outputs": [], + "source": [ + "class Car:\n", + "\n", + " color = \"red\"\n", + "\n", + " def __init__(self):\n", + " print(f\"The car is going fast.\")" + ] + }, + { + "cell_type": "code", + "execution_count": 168, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The car is going fast.\n" + ] + } + ], + "source": [ + "a = Car()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Defining Attributes & Methods" + ] + }, + { + "cell_type": "code", + "execution_count": 169, + "metadata": {}, + "outputs": [], + "source": [ + "class Car:\n", + "\n", + " color = \"red\"\n", + "\n", + " def __init__(self):\n", + " print(f\"The car is going fast.\")\n", + "\n", + " def drive(self, how_fast):\n", + " return f\"The {self.color} car drives {how_fast} mph.\"" + ] + }, + { + "cell_type": "code", + "execution_count": 170, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The car is going fast.\n", + "The car is going fast.\n" + ] + } + ], + "source": [ + "car_a = Car()\n", + "car_b = Car()" + ] + }, + { + "cell_type": "code", + "execution_count": 171, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'red'" + ] + }, + "execution_count": 171, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "car_a.color" + ] + }, + { + "cell_type": "code", + "execution_count": 172, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'red'" + ] + }, + "execution_count": 172, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "car_b.color" + ] + }, + { + "cell_type": "code", + "execution_count": 173, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'The red car drives 55 mph.'" + ] + }, + "execution_count": 173, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "car_b.drive(55)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# `self` - Setting Attributes & Methods" + ] + }, + { + "cell_type": "code", + "execution_count": 174, + "metadata": {}, + "outputs": [], + "source": [ + "class Car:\n", + "\n", + " def __init__(self, color, make):\n", + " self.color = color\n", + " self.color_cap = color.upper()\n", + " self.make = make\n", + "\n", + " def mph_to_kph(self, mph):\n", + " return mph * 1.60934\n", + "\n", + " def drive(self, how_fast):\n", + " return f\"The {self.color} {self.make} drives {how_fast} mph.\"\n", + "\n", + " def drive_in_kph(self, how_fast):\n", + " kph = self.mph_to_kph(how_fast)\n", + " return f\"The {self.color} {self.make} drives {kph} kph.\"" + ] + }, + { + "cell_type": "code", + "execution_count": 175, + "metadata": {}, + "outputs": [], + "source": [ + "car_a = Car(\"Black\", \"Tahoe\")" + ] + }, + { + "cell_type": "code", + "execution_count": 176, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'The Black Tahoe drives 88.5137 kph.'" + ] + }, + "execution_count": 176, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "car_a.drive_in_kph(55)" + ] + }, + { + "cell_type": "code", + "execution_count": 177, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'The Black Audi drives 160.934 kph.'" + ] + }, + "execution_count": 177, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "car_b = Car(\"Black\", \"Audi\")\n", + "car_b.drive_in_kph(100)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.5" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/build/conda/installer/assets/header_win.png b/build/conda/installer/assets/header_win.png new file mode 100644 index 0000000000000000000000000000000000000000..f7ffd7ea723b277a9fca030d304f1717bec1241f Binary files /dev/null and b/build/conda/installer/assets/header_win.png differ diff --git a/build/conda/installer/assets/installer.nsi b/build/conda/installer/assets/installer.nsi new file mode 100644 index 0000000000000000000000000000000000000000..65506d5e8a08fc82126a3c77f3953a8bd509a78b --- /dev/null +++ b/build/conda/installer/assets/installer.nsi @@ -0,0 +1,264 @@ +;-------------------------------- +; Includes + + !include "MUI2.nsh" + !include "logiclib.nsh" + + +#if enable_debugging is True +# Special logging build needed for ENABLE_LOGGING +#ย See https://nsis.sourceforge.io/Special_Builds +!define ENABLE_LOGGING=True +#endif + +# Comes from https://nsis.sourceforge.io/Logging:Enable_Logs_Quickly +!define LogSet "!insertmacro LogSetMacro" +!macro LogSetMacro SETTING + !ifdef ENABLE_LOGGING + LogSet ${SETTING} + !endif +!macroend + +!define LogText "!insertmacro LogTextMacro" +!macro LogTextMacro INPUT_TEXT + !ifdef ENABLE_LOGGING + LogText ${INPUT_TEXT} + !endif +!macroend + +;-------------------------------- +; Custom defines + !define NAME "OpenBB Platform" + !define COMPANY "OpenBB" + !define VERSION "1.0.0" + !define SLUG "${NAME} v${VERSION}" + +;-------------------------------- +; General + Name "${NAME}" + InstallDir "${PROFILE}\OpenBB" + RequestExecutionLevel user + +;-------------------------------- +; UI + + !define MUI_ICON "assets\openbb_icon.ico" + !define MUI_UNICON "assets\openbb_icon.ico" + !define MUI_HEADERIMAGE + !define MUI_WELCOMEFINISHPAGE_BITMAP "assets\installer_vertical2.bmp" + !define MUI_HEADERIMAGE_BITMAP "assets\installer_horizontal.bmp" + !define MUI_ABORTWARNING + !define MUI_WELCOMEPAGE_TITLE "${SLUG} Setup" + !define UninstId "OpenBBPlatform" ; You might want to use a GUID here + +;-------------------------------- +; Pages + + ; Installer pages + !insertmacro MUI_PAGE_WELCOME + !insertmacro MUI_PAGE_LICENSE "assets\installer_license.txt" +; !insertmacro MUI_PAGE_COMPONENTS + !insertmacro MUI_PAGE_DIRECTORY + !insertmacro MUI_PAGE_INSTFILES + !insertmacro MUI_PAGE_FINISH + + ; Uninstaller pages + !insertmacro MUI_UNPAGE_CONFIRM + !insertmacro MUI_UNPAGE_INSTFILES + + ; Set UI language + !insertmacro MUI_LANGUAGE "English" + + + ; Var /GLOBAL installerPath + + + + + +; StrContains +; This function does a case sensitive searches for an occurrence of a substring in a string. +; It returns the substring if it is found. +; Otherwise it returns null(""). +; Written by kenglish_hi +; Adapted from StrReplace written by dandaman32 + + +Var STR_HAYSTACK +Var STR_NEEDLE +Var STR_CONTAINS_VAR_1 +Var STR_CONTAINS_VAR_2 +Var STR_CONTAINS_VAR_3 +Var STR_CONTAINS_VAR_4 +Var STR_RETURN_VAR + +Function StrContains + Exch $STR_NEEDLE + Exch 1 + Exch $STR_HAYSTACK + ; Uncomment to debug + ;MessageBox MB_OK 'STR_NEEDLE = $STR_NEEDLE STR_HAYSTACK = $STR_HAYSTACK ' + StrCpy $STR_RETURN_VAR "" + StrCpy $STR_CONTAINS_VAR_1 -1 + StrLen $STR_CONTAINS_VAR_2 $STR_NEEDLE + StrLen $STR_CONTAINS_VAR_4 $STR_HAYSTACK + loop: + IntOp $STR_CONTAINS_VAR_1 $STR_CONTAINS_VAR_1 + 1 + StrCpy $STR_CONTAINS_VAR_3 $STR_HAYSTACK $STR_CONTAINS_VAR_2 $STR_CONTAINS_VAR_1 + StrCmp $STR_CONTAINS_VAR_3 $STR_NEEDLE found + StrCmp $STR_CONTAINS_VAR_1 $STR_CONTAINS_VAR_4 done + Goto loop + found: + StrCpy $STR_RETURN_VAR $STR_NEEDLE + Goto done + done: + Pop $STR_NEEDLE ;Prevent "invalid opcode" errors and keep the + Exch $STR_RETURN_VAR +FunctionEnd + +!macro _StrContainsConstructor OUT NEEDLE HAYSTACK + Push `${HAYSTACK}` + Push `${NEEDLE}` + Call StrContains + Pop `${OUT}` +!macroend + +!define StrContains '!insertmacro "_StrContainsConstructor"' + + +;------------------------------- +; Uninstall Previous Version if exists + +!macro UninstallExisting exitcode uninstcommand +Push `${uninstcommand}` +Call UninstallExisting +Pop ${exitcode} +!macroend +Function UninstallExisting +Exch $1 ; uninstcommand +Push $2 ; Uninstaller +Push $3 ; Len +StrCpy $3 "" +StrCpy $2 $1 1 +StrCmp $2 '"' qloop sloop +sloop: + StrCpy $2 $1 1 $3 + IntOp $3 $3 + 1 + StrCmp $2 "" +2 + StrCmp $2 ' ' 0 sloop + IntOp $3 $3 - 1 + Goto run +qloop: + StrCmp $3 "" 0 +2 + StrCpy $1 $1 "" 1 ; Remove initial quote + IntOp $3 $3 + 1 + StrCpy $2 $1 1 $3 + StrCmp $2 "" +2 + StrCmp $2 '"' 0 qloop +run: + StrCpy $2 $1 $3 ; Path to uninstaller + StrCpy $1 161 ; ERROR_BAD_PATHNAME + GetFullPathName $3 "$2\.." ; $InstDir + IfFileExists "$2" 0 +4 + ExecWait '"$2" /S _?=$3' $1 ; This assumes the existing uninstaller is a NSIS uninstaller, other uninstallers don't support /S nor _?= + IntCmp $1 0 "" +2 +2 ; Don't delete the installer if it was aborted + Delete "$2" ; Delete the uninstaller + RMDir "$3" ; Try to delete $InstDir + RMDir "$3\.." ; (Optional) Try to delete the parent of $InstDir +Pop $3 +Pop $2 +Exch $1 ; exitcode +FunctionEnd + + +Function .onInit +ReadRegStr $0 HKCU "Software\Software\Microsoft\Windows\CurrentVersion\Uninstall\${UninstId}" "UninstallString" +${If} $0 != "" +${AndIf} ${Cmd} `MessageBox MB_YESNO|MB_ICONQUESTION "It is highly recommended to uninstall the previous version of OpenBB Terminal - Please click Yes to proceed (Note - You will not lose your custom settings) - Or you can uninstall manually. " /SD IDYES IDYES` + !insertmacro UninstallExisting $0 $0 + ${If} $0 <> 0 + MessageBox MB_YESNO|MB_ICONSTOP "Failed to uninstall, continue anyway?" /SD IDYES IDYES +2 + Abort + ${EndIf} +${EndIf} +FunctionEnd + +;-------------------------------- +; Section - Install App + + Section "-hidden app" + SectionIn RO + ${StrContains} $0 "\OpenBB" "$INSTDIR" + ; Making sure here if user manually removes \openbb from their path that it still installs there + ; so we dont have issues with uninstaller later. + StrCmp $0 "" notfound + ; MessageBox MB_OK 'Found string $0 $INSTDIR' + SetOutPath "$INSTDIR" + Goto done + notfound: + ; MessageBox MB_OK "$INSTDIR is 'bla'" + SetOutPath "$INSTDIR\OpenBB" + StrCpy $InstDir "$INSTDIR\OpenBB" + ; MessageBox MB_OK 'Did not find string "$INSTDIR\OpenBB" "$installerPath"' + done: + + ; File /r "app\*.*" + WriteRegStr HKCU "Software\${NAME}" "" $INSTDIR + WriteUninstaller "$INSTDIR\Uninstall.exe" + WriteRegStr HKCU "Software\Software\Microsoft\Windows\CurrentVersion\Uninstall\${UninstId}" "OpenBBPlatform" "OpenBB" + WriteRegStr HKCU "Software\Software\Microsoft\Windows\CurrentVersion\Uninstall\${UninstId}" "UninstallString" '"$InstDir\Uninstall.exe"' + WriteRegStr HKCU "Software\Software\Microsoft\Windows\CurrentVersion\Uninstall\${UninstId}" "QuietUninstallString" '"$InstDir\Uninstall.exe" /S' + SectionEnd + + +;-------------------------------- +; Remove empty parent directories + + Function un.RMDirUP + !define RMDirUP '!insertmacro RMDirUPCall' + + !macro RMDirUPCall _PATH + push '${_PATH}' + Call un.RMDirUP + !macroend + + ; $0 - current folder + ClearErrors + + Exch $0 + ;DetailPrint "ASDF - $0\.." + RMDir "$0\.." + + IfErrors Skip + ${RMDirUP} "$0\.." + Skip: + + Pop $0 + + FunctionEnd + +;-------------------------------- +; Section - Uninstaller + +Section "Uninstall" + + ;Delete Shortcut + Delete "$DESKTOP\${NAME}.lnk" + + ;Delete Directory + Delete '$SMPROGRAMS\${Company}\${NAME}' + + ;Delete Reg Key + DeleteRegKey HKCU "Software\Software\Microsoft\Windows\CurrentVersion\Uninstall\${UninstId}" + + ;Delete Uninstall + Delete "$INSTDIR\Uninstall.exe" + + + ;Delete Folder + RMDir /r "$INSTDIR" + ${RMDirUP} "$INSTDIR" + + DeleteRegKey /ifempty HKCU "Software\${NAME}" + +SectionEnd \ No newline at end of file diff --git a/build/conda/installer/assets/installer_conclusion.txt b/build/conda/installer/assets/installer_conclusion.txt new file mode 100644 index 0000000000000000000000000000000000000000..799b09ceb948aadf890a85fdad920c63f0d92474 --- /dev/null +++ b/build/conda/installer/assets/installer_conclusion.txt @@ -0,0 +1,12 @@ +Thank you for installing OpenBB Platform! + +To get started, open the installed OpenBB folder, in the home folder of your user, and review the README.md file. Or, open one of the launchers using the provided shortcuts. + +The OpenBB Platform Documentation is found here: +https://docs.openbb.co + +Bugs/Issues/Requests can be posted here: +https://github.com/OpenBB-finance/OpenBB/issues + +Security vulnerabilities can be reported here: +https://github.com/OpenBB-finance/OpenBB/security/advisories diff --git a/build/conda/installer/assets/installer_license.txt b/build/conda/installer/assets/installer_license.txt new file mode 100644 index 0000000000000000000000000000000000000000..0749d9bc616a07fe1a25ab52f981da85c3101c25 --- /dev/null +++ b/build/conda/installer/assets/installer_license.txt @@ -0,0 +1,661 @@ +GNU AFFERO GENERAL PUBLIC LICENSE +Version 3, 19 November 2007 + +Copyright (C) 2007 Free Software Foundation, Inc. +Everyone is permitted to copy and distribute verbatim copies +of this license document, but changing it is not allowed. + +Preamble + +The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + +The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + +When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + +Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + +A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + +The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + +An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + +The precise terms and conditions for copying, distribution and +modification follow. + +TERMS AND CONDITIONS + +1. Definitions. + +"This License" refers to version 3 of the GNU Affero General Public License. + +"Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + +"The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + +To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + +A "covered work" means either the unmodified Program or a work based +on the Program. + +To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + +To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + +An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + +1. Source Code. + +The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + +A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + +The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + +The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + +The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + +The Corresponding Source for a work in source code form is that +same work. + +2. Basic Permissions. + +All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + +You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + +Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + +3. Protecting Users' Legal Rights From Anti-Circumvention Law. + +No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + +When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + +4. Conveying Verbatim Copies. + +You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + +You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + +5. Conveying Modified Source Versions. + +You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + +A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + +6. Conveying Non-Source Forms. + +You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + +A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + +A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + +"Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + +If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + +The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + +Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + +7. Additional Terms. + +"Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + +When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + +Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + +All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + +If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + +Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + +8. Termination. + +You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + +However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + +Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + +Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + +9. Acceptance Not Required for Having Copies. + +You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + +10. Automatic Licensing of Downstream Recipients. + +Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + +An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + +You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + +11. Patents. + +A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + +A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + +Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + +In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + +If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + +If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + +A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + +Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + +12. No Surrender of Others' Freedom. + +If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + +13. Remote Network Interaction; Use with the GNU General Public License. + +Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + +Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + +14. Revised Versions of this License. + +The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + +If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + +Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + +15. Disclaimer of Warranty. + +THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +16. Limitation of Liability. + +IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + +17. Interpretation of Sections 15 and 16. + +If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + +END OF TERMS AND CONDITIONS + +How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + +If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. + +You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU AGPL, see +. diff --git a/build/conda/installer/assets/installer_readme.txt b/build/conda/installer/assets/installer_readme.txt new file mode 100644 index 0000000000000000000000000000000000000000..0fcb5311926bb3429d042f2a19fd44ee13ea245b --- /dev/null +++ b/build/conda/installer/assets/installer_readme.txt @@ -0,0 +1,19 @@ +OpenBB Platform provides a convenient way to access raw financial data from multiple data providers. + +Important Notes: + +In order to install you need access to the Internet. + +The installation will take approximately 1-2 GB of storage and is for the current user only, system-wide installations are not allowed. + +If a folder named "OpenBB" already exists at the user home directory, please remove it before installing. + +The installed packages can be reconfigured, post-installation, for custom configurations. + +If the OpenBB folder is moved, post-installation, the shortcuts will not be updated to reflect the change. + + + +This application is intended strictly for research and educational purposes. + +By proceeding with the installation, you agree not to use this application for any purpose that is unlawful or prohibited by international and national laws, regulations, or governmental and industry requirements. diff --git a/build/conda/installer/assets/installer_welcome.txt b/build/conda/installer/assets/installer_welcome.txt new file mode 100644 index 0000000000000000000000000000000000000000..7c73834656822b35964dfb965ecbdb2d6d9b3382 --- /dev/null +++ b/build/conda/installer/assets/installer_welcome.txt @@ -0,0 +1,8 @@ +Welcome to the OpenBB Platform Installer. + + +This application will install the latest version of the OpenBB Platform on your computer in a self-contained, Python 3.12, Conda environment. It contains everything required to get started immediately, both as a user and a developer. + +Several launch scripts are included; OpenBB CLI, OpenBB API, Jupyter Notebook, IPython, Update, and shortcuts to key folders. + +Find them at the base of the installation folder, along with the README.md file for getting started. diff --git a/build/conda/installer/assets/openbb.icns b/build/conda/installer/assets/openbb.icns new file mode 100644 index 0000000000000000000000000000000000000000..d02e2301f45fcec1df7fc04f4322df8a53f77591 Binary files /dev/null and b/build/conda/installer/assets/openbb.icns differ diff --git a/build/conda/installer/assets/openbb_icon.ico b/build/conda/installer/assets/openbb_icon.ico new file mode 100644 index 0000000000000000000000000000000000000000..ec1a7d484f45fe4167e76d75284938679bcb3aff Binary files /dev/null and b/build/conda/installer/assets/openbb_icon.ico differ diff --git a/build/conda/installer/assets/openbb_osx.png b/build/conda/installer/assets/openbb_osx.png new file mode 100644 index 0000000000000000000000000000000000000000..2682eca85f7d7c253418e6cee5dd30c4b048e859 Binary files /dev/null and b/build/conda/installer/assets/openbb_osx.png differ diff --git a/build/conda/installer/assets/openbb_platform_installer/README.md b/build/conda/installer/assets/openbb_platform_installer/README.md new file mode 100644 index 0000000000000000000000000000000000000000..2aa6233b823a8b417707039acb94daf78a367686 --- /dev/null +++ b/build/conda/installer/assets/openbb_platform_installer/README.md @@ -0,0 +1,48 @@ +# OpenBB Platform Installer Package + +This package is for installing the OpenBB Platform packages into any Python environment. Versions between 3.9 and 3.12, inclusively, are supported. + +The `obb` virtual environment that came with the installation is pre-loaded, and this configuration can be duplicated by creating a new environment and running, `poetry install`, from this location. + +## Installation + +Assuming the current working directory is the location of this document, the code block below will create a new environment, activate it, update the dependencies, and then install the OpenBB Platform. + +Open the Terminal command line with the Bash/CMD shortcut. + +```sh +conda create -n my_env python=3.10 -y +conda activate my_env +pip install poetry +poetry lock +poetry install +openbb-build +``` + +## Updating Packages + +Update the environment dependencies with: + +```sh +poetry lock +poetry install +``` + +## Installation Groups + +The package can be installed in different configurations, using Poetry groups as `--with`, `--without`, or `--only` keyword arguments. + +- main +- openbb-all +- cli +- notebook + +To install, in a fresh environment, only the `openbb-core` package and the base dependencies: + +```sh +poetry install --only main --sync +``` + +The `--sync` flag with sync the environment to the `poetry.lock` file for the flagged group(s). All items are installed when no arguments are supplied. Use this as a way to restore corrupted environments. + +Do not use the `--sync` flag if you wish to keep installed packages that are not defined in the `pyproject.toml` and `poetry.lock` files. diff --git a/build/conda/installer/assets/openbb_platform_installer/obb-env.yml b/build/conda/installer/assets/openbb_platform_installer/obb-env.yml new file mode 100644 index 0000000000000000000000000000000000000000..a201e45b581a8f20b73ea33cfc85af847fa9f83f --- /dev/null +++ b/build/conda/installer/assets/openbb_platform_installer/obb-env.yml @@ -0,0 +1,5 @@ +name: obb +channels: + - conda-forge +dependencies: + - python=3.12 \ No newline at end of file diff --git a/build/conda/installer/assets/openbb_platform_installer/openbb_platform_installer/__init__.py b/build/conda/installer/assets/openbb_platform_installer/openbb_platform_installer/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..d4cda538012605d75ce57f1e86667b6156355509 --- /dev/null +++ b/build/conda/installer/assets/openbb_platform_installer/openbb_platform_installer/__init__.py @@ -0,0 +1,3 @@ +"""Placeholder for the OpenBB Platform Installer package.""" + +__version__ = "1.0.2" diff --git a/build/conda/installer/assets/openbb_platform_installer/openbb_platform_installer/update.py b/build/conda/installer/assets/openbb_platform_installer/openbb_platform_installer/update.py new file mode 100644 index 0000000000000000000000000000000000000000..4c3b4feba1508aea1af59c91c87807acb8c35cf7 --- /dev/null +++ b/build/conda/installer/assets/openbb_platform_installer/openbb_platform_installer/update.py @@ -0,0 +1,30 @@ +"""Entry point for the OpenBB Updater script.""" + +# pylint: disable=import-outside-toplevel,unused-import +# flake8: noqa + +def main(): + """Update the OpenBB Platform and rebuild the Python interface.""" + + import os + import sys + import subprocess + from pathlib import Path + + args = os.sys.argv[1:].copy() if os.sys.argv[1:] else [] + + cwd = Path(os.path.dirname(os.path.realpath(__file__))).parent.resolve() + + command = ( + f"{sys.executable} -m pip install -U pip && " + f"{sys.executable} -m poetry lock && " + f"{sys.executable} -m poetry install {' '.join(args)} && " + "openbb-build" + ) + + subprocess.run(command, shell=True, cwd=cwd) + + input("\nUpdate complete. Press Enter to exit...") + +if __name__ == "__main__": + main() diff --git a/build/conda/installer/assets/openbb_platform_installer/pyproject.toml b/build/conda/installer/assets/openbb_platform_installer/pyproject.toml new file mode 100644 index 0000000000000000000000000000000000000000..7246979da5e1976b499a1793f723b036e3d607ed --- /dev/null +++ b/build/conda/installer/assets/openbb_platform_installer/pyproject.toml @@ -0,0 +1,40 @@ +# If you will be using this as a template for your own package, please change the values accordingly. +[tool.poetry] +name = "openbb_platform_installer" # Change this to your package name +version = "1.0.3" # Change this to your package version +description = "A meta package for installing the OpenBB Platform: Investment research for everyone, anywhere." # Change this to your description +authors = ["OpenBB "] # Change this to your name and email +license = "AGPL-3.0-only" # This license must be compatible with the OpenBB license +readme = "README.md" # Change this to your README file +homepage = "https://openbb.co" # Change this to your website +repository = "https://github.com/openbb-finance/openbb" # Change this to your repository +documentation = "https://docs.openbb.co" # Change this to your documentation +packages = [{ include = "openbb_platform_installer" }] # Update accordingly - these are build scripts and entry points. + +[tool.poetry.scripts] +openbb-update = "openbb_platform_installer.update:main" + +[tool.poetry.dependencies] +python = ">=3.9.21,<3.13" +openbb-platform-api = "^1.1.8" + +[tool.poetry.group.openbb-all] + +[tool.poetry.group.openbb-all.dependencies] +openbb = { version = "^4.4.4", extras = ["all"] } + +[tool.poetry.group.cli] + +[tool.poetry.group.cli.dependencies] +openbb-cli = "^1" + +[tool.poetry.group.notebook] + +[tool.poetry.group.notebook.dependencies] +notebook = "^7" +nbclassic = "^1" +jedi-language-server = "^0.41" + +[build-system] +requires = ["poetry-core>=1.0.0"] +build-backend = "poetry.core.masonry.api" diff --git a/build/conda/installer/assets/openbb_win.png b/build/conda/installer/assets/openbb_win.png new file mode 100644 index 0000000000000000000000000000000000000000..c8540d22fc795051c25148c213b27c0bd0bebf2b Binary files /dev/null and b/build/conda/installer/assets/openbb_win.png differ diff --git a/build/conda/installer/construct.yaml b/build/conda/installer/construct.yaml new file mode 100644 index 0000000000000000000000000000000000000000..25ddbbee57917e434a3311938d14a8b13e3501f3 --- /dev/null +++ b/build/conda/installer/construct.yaml @@ -0,0 +1,95 @@ +name: "OpenBB" +version: "Platform" +company: OpenBB, Inc. +license_file: ./assets/installer_license.txt + +installer_type: all + +register_python: false # [win] +register_python_default: false # [win] +register_envs: false +initialize_by_default: false +initialize_conda: false +write_condarc: true + +default_location_pkg: OpenBB # [osx] +default_prefix_domain_user: "%USERPROFILE%\\OpenBB\\conda" # [win] +default_prefix: "${HOME}/OpenBB" # [linux] +default_prefix: "%USERPROFILE%\\OpenBB\\conda" # [win] +pkg_name: conda + +specs: + - conda + - bash # [unix] + - python=3.12 + +extra_envs: + obb: + environment_file: ./assets/openbb_platform_installer/obb-env.yml + +channels: + - conda-forge + +condarc: + {channels: [conda-forge], + allow_softlinks: false, + auto_activate_base: false, + always_copy: true, + register_envs: false, + pip_interop_enabled: true} + +pkg_domains: + enable_anywhere: false + enable_currentUserHome: true + +post_install: post_install.sh # [unix] +post_install: post_install.bat # [win] + +extra_files: + # Bundle launcher assets + - ./README.md: ../README.md + - ./assets/openbb_platform_installer/obb-env.yml: ../extensions/openbb_platform_installer/obb-env.yml + - ./assets/openbb_platform_installer/pyproject.toml: ../extensions/openbb_platform_installer/pyproject.toml + - ./assets/openbb_platform_installer/README.md: ../extensions/openbb_platform_installer/README.md + - ./assets/openbb_platform_installer/openbb_platform_installer/__init__.py: ../extensions/openbb_platform_installer/openbb_platform_installer/__init__.py + - ./assets/openbb_platform_installer/openbb_platform_installer/update.py: ../extensions/openbb_platform_installer/openbb_platform_installer/update.py + - ./assets/openbb_icon.ico: assets/openbb_icon.ico # [win] + - ./assets/openbb.icns: ../openbb_icon.icns # [osx] + - ./assets/create_shortcut.vbs: assets/create_shortcut.vbs # [win] + - ./assets/installer_license.txt: assets/installer_license.txt # [win] + - ./assets/installer_vertical2.bmp: assets/installer_vertical2.bmp # [win] + - ./assets/installer_horizontal.bmp: assets/installer_horizontal.bmp # [win] + - ./assets/examples/README.md: ../extensions/examples/README.md + - ./assets/examples/install_examples.py: ../extensions/examples/install_examples.py + - ./assets/examples/empty_provider/pyproject.toml: ../extensions/examples/empty_provider/pyproject.toml + - ./assets/examples/empty_provider/README.md: ../extensions/examples/empty_provider/README.md + - ./assets/examples/empty_provider/empty_provider/__init__.py: ../extensions/examples/empty_provider/empty_provider/__init__.py + - ./assets/examples/empty_provider/empty_provider/models/__init__.py: ../extensions/examples/empty_provider/empty_provider/models/__init__.py + - ./assets/examples/empty_provider/empty_provider/models/empty_model.py: ../extensions/examples/empty_provider/empty_provider/models/empty_model.py + - ./assets/examples/empty_provider/empty_provider/utils/__init__.py: ../extensions/examples/empty_provider/empty_provider/utils/__init__.py + - ./assets/examples/empty_router/pyproject.toml: ../extensions/examples/empty_router/pyproject.toml + - ./assets/examples/empty_router/README.md: ../extensions/examples/empty_router/README.md + - ./assets/examples/empty_router/empty_router/__init__.py: ../extensions/examples/empty_router/empty_router/__init__.py + - ./assets/examples/empty_router/empty_router/empty_router.py: ../extensions/examples/empty_router/empty_router/empty_router.py + - ./assets/examples/empty_router/empty_router/empty_views.py: ../extensions/examples/empty_router/empty_router/empty_views.py + - ./assets/examples/empty_obbject/pyproject.toml: ../extensions/examples/empty_obbject/pyproject.toml + - ./assets/examples/empty_obbject/README.md: ../extensions/examples/empty_obbject/README.md + - ./assets/examples/empty_obbject/empty_obbject/__init__.py: ../extensions/examples/empty_obbject/empty_obbject/__init__.py + - ./assets/examples/python_basics.ipynb: ../notebooks/python_basics.ipynb + - ../../../examples/platform_standardization.ipynb: ../notebooks/how_platform_works.ipynb + +icon_image: ../openbb_icon.icns # [osx] +icon_image: ./assets/openbb_icon.ico # [win] +welcome_image: ./assets/openbb_osx.png # [unix] +welcome_image: ./assets/Installer_vertical2.bmp # [win] +header_image: ./assets/Installer_horizontal2.png # [win] +welcome_image_text: "OpenBB Platform" +readme_file: ./assets/installer_readme.txt # [unix] +conclusion_file: ./assets/installer_conclusion.txt # [unix] +welcome_file: ./assets/installer_welcome.txt # [unix] +welcome_file: ./assets/custom_welcome.nsi # [win] +conclusion_file: ./assets/custom_conclusion.nsi # [win] + +# Add extra files to the installer - this is another way - was playing with this +temp_extra_files: + - ./assets/Installer_vertical2.bmp: Installer_vertical2.bmp # [win] diff --git a/build/conda/installer/post_install.bat b/build/conda/installer/post_install.bat new file mode 100644 index 0000000000000000000000000000000000000000..0373ff0a15d76e08de00789edb3aec3f81f42564 --- /dev/null +++ b/build/conda/installer/post_install.bat @@ -0,0 +1,61 @@ +@echo off +echo Installing environment, this may take a few minutes... Watch for changes in post_install_log.txt file at the root of the installation directory. + +cd "%PREFIX%\..\extensions\openbb_platform_installer" + +PATH %PREFIX%;%PREFIX%\Scripts;%PREFIX%\Library\bin;%PATH% +SET LOG_FILE="%PREFIX%\..\post_install_log.txt" + +call "%PREFIX%\Scripts\activate.bat" + +call conda activate "%PREFIX%\envs\obb" >> "%LOG_FILE%" 2>&1 + +python -m pip install -U pip >> "%LOG_FILE%" 2>&1 + +pip install -U setuptools >> "%LOG_FILE%" 2>&1 + +pip install poetry >> "%LOG_FILE%" 2>&1 + +poetry config virtualenvs.path "%PREFIX%\envs" --local >> "%LOG_FILE%" 2>&1 + +poetry config virtualenvs.create false --local >> "%LOG_FILE%" 2>&1 + +poetry lock >> "%LOG_FILE%" 2>&1 + +poetry install >> "%LOG_FILE%" 2>&1 + +IF ERRORLEVEL 1 ( + echo %date% %time% "Error during post-installation: poetry install failed." >> %LOG_FILE% + exit /b 1 +) ELSE ( + echo %date% %time% "Python environment successfully installed... Building the OpenBB Python interface..." >> %LOG_FILE% +) + +echo Python environment successfully installed... Building the OpenBB Python interface... + +call openbb-build >> "%LOG_FILE%" 2>&1 +IF ERRORLEVEL 1 ( + call :log_with_timestamp "Error during post-installation: building OpenBB's Python interface failed." + exit /b 1 +) ELSE ( + call :log_with_timestamp "OpenBB's Python interface built successfully." +) + +cscript "%PREFIX%\assets\create_shortcut.vbs" >> "%LOG_FILE%" 2>&1 +IF ERRORLEVEL 1 ( + echo %date% %time% "Error during post-installation: creating shortcuts failed." >> %LOG_FILE% + exit /b 1 +) ELSE ( + echo %date% %time% "Shortcuts created successfully." >> %LOG_FILE% +) + +echo Post-installation steps completed successfully. + +exit /b 0 + +goto :eof + +REM Function to add timestamp +:log_with_timestamp + echo %date%_%time% %1 >> %LOG_FILE% + goto :eof \ No newline at end of file diff --git a/build/conda/installer/post_install.sh b/build/conda/installer/post_install.sh new file mode 100644 index 0000000000000000000000000000000000000000..00f115508073066a51770bff124a41a9f6b5f5d2 --- /dev/null +++ b/build/conda/installer/post_install.sh @@ -0,0 +1,158 @@ +#!/bin/bash + +# Setup environment. +export PATH="$PREFIX/bin:$PATH" +LOG_FILE="$PREFIX/../post_install_log.txt" + +# Function to add timestamp. +log_with_timestamp() { + echo "$(date '+%Y-%m-%d_%H:%M:%S') $1" >>"$LOG_FILE" +} + +cd "$PREFIX/../extensions/openbb_platform_installer" >>"$LOG_FILE" 2>&1 + +source "$PREFIX/etc/profile.d/conda.sh" && conda activate "$PREFIX" + +conda activate obb >>"$LOG_FILE" 2>&1 + +python -m pip install -U pip >>"$LOG_FILE" 2>&1 + +pip install -U setuptools poetry >>"$LOG_FILE" 2>&1 + +pip install poetry >>"$LOG_FILE" 2>&1 + +poetry config virtualenvs.path "$PREFIX/envs" --local >>"$LOG_FILE" 2>&1 + +poetry config virtualenvs.create false --local >>"$LOG_FILE" 2>&1 + +poetry lock >>"$LOG_FILE" 2>&1 + + +# Install OpenBB packages. +if poetry install >>"$LOG_FILE" 2>&1; then + log_with_timestamp "OpenBB Platform installation completed successfully." +else + log_with_timestamp "Error during post-installation: poetry install failed." + exit 1 +fi + +# Build OpenBB Python interface. +python - <>"$LOG_FILE" 2>&1 +import openbb +openbb.build() +EOF +log_with_timestamp "OpenBB's Python Interface built successfully." + +# IPython launcher script initialized with OpenBB. +IPYTHON_WRAPPER_SCRIPT="$PREFIX/envs/obb/bin/openbb-ipython-launcher" + +cat > "$IPYTHON_WRAPPER_SCRIPT" < "$SHELL_WRAPPER_SCRIPT" < "$NOTEBOOK_WRAPPER_SCRIPT" < "$API_WRAPPER_SCRIPT" < "$CLI_WRAPPER_SCRIPT" < "$OPENBB_UPDATER_SCRIPT" <>"$LOG_FILE" 2>&1 +else + log_with_timestamp "Error during post-installation: creating symlinks failed." >>"$LOG_FILE" 2>&1 +fi + +verify_symlink() { + if [ -L "$1" ] && [ -e "$1" ]; then + log_with_timestamp "Symlink $1 verified successfully." + else + log_with_timestamp "Error: Symlink $1 is not working." + exit 1 + fi +} + +verify_symlink "$TARGET_DIR/openbb-cli" +verify_symlink "$TARGET_DIR/openbb-api" +verify_symlink "$TARGET_DIR/openbb-notebook" +verify_symlink "$TARGET_DIR/openbb-ipython" +verify_symlink "$TARGET_DIR/Bash" +verify_symlink "$TARGET_DIR/Update" +verify_symlink "$TARGET_DIR/Settings" +verify_symlink "$TARGET_DIR/OpenBBUserData" +verify_symlink "$TARGET_DIR/Environments" diff --git a/build/docker/platform.dockerfile b/build/docker/platform.dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..3bbfb2ae4362dae6a963110e0d95de1eb21200d7 --- /dev/null +++ b/build/docker/platform.dockerfile @@ -0,0 +1,47 @@ +# ---- Base Python ---- + FROM python:3.11-slim-bullseye AS base + + # set work directory + WORKDIR /openbb + + # set environment variables + ENV PYTHONDONTWRITEBYTECODE 1 + ENV PYTHONUNBUFFERED 1 + + # install dependencies + RUN apt-get update \ + && apt-get install -y --no-install-recommends build-essential openssh-client curl \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + + # install toml and poetry + RUN pip install toml poetry + + # ---- Copy Files/Build ---- + FROM base AS builder + + WORKDIR /openbb + + # install Rust + RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \ + && apt-get update \ + && apt-get install -y --no-install-recommends libwebkit2gtk-4.0-dev \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + + # add Rust to PATH + ENV PATH="/root/.cargo/bin:${PATH}" + + COPY ./openbb_platform ./openbb_platform + + # Install the Platform + RUN pip install /openbb/openbb_platform[all] + RUN pip install openbb-devtools + + # ---- Copy Files ---- + FROM base + + COPY --from=builder /usr/local /usr/local + + # Launch the API + CMD ["uvicorn", "openbb_core.api.rest_api:app", "--host", "0.0.0.0", "--port", "8000", "--reload"] diff --git a/build/docker/platformAPI.Dockerfile b/build/docker/platformAPI.Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..c853138a5f1d217c5ffabe146a4db01ff306a30a --- /dev/null +++ b/build/docker/platformAPI.Dockerfile @@ -0,0 +1,10 @@ +FROM python:3.10-slim-bookworm + +WORKDIR /app + +RUN pip install "openbb[all]" +RUN pip install openbb-platform-api + +EXPOSE 6900 + +ENTRYPOINT ["openbb-api", "--host", "0.0.0.0", "--login"] diff --git a/build/pypi/openbb_platform/PUBLISH.md b/build/pypi/openbb_platform/PUBLISH.md new file mode 100644 index 0000000000000000000000000000000000000000..ed4fc310814d03d9dbb5957bc02e866b1c5ea46a --- /dev/null +++ b/build/pypi/openbb_platform/PUBLISH.md @@ -0,0 +1,60 @@ +# Publishing to PyPI + +## Pre-release + +> [!WARNING] +> The `release` branch is solely for the purpose of publishing the package(s)! Any last minute changes should be made in appropriate PRs and merged to the `develop` branch. Once the `release` branch is created, the `develop` branch should be frozen for further commits until this process finishes. + +> A `release` branch for a particular package should only cater to the changes for that package directory. For e.g. the `release/openbb-core-2.0.0` branch should only contain changes for the `openbb-core` package i.e. in the `openbb_platform/core` directory. + +0. Merge `main` into `develop` and solve any conflict. You can do this by checking out `develop`, creating a branch `feature/merge-main-into-develop` and running `git merge main`. Merge this into `develop` if there are changes to commit. +1. Open a PR with the changes to be published in the format `release/` (for e.g. `release/4.0.0` ). For a particular package use the format `release/-` (for e.g. `release/openbb-core-1.0.1`). +2. Bump `openbb` package version in `openbb_platform/pyproject.toml`. + +> [!WARNING] +> The version must be incremented before running the tests in 4. and 5., since there are tests that rely of this to check for deprecated endpoints. Pay attention to commands that should be deprecated in the version you will publish. + +3. Ensure all the CI workflows pass. +4. Ensure all unit tests pass: `pytest openbb_platform -m "not integration"` +5. Ensure all integration tests pass: `pytest openbb_platform -m integration` + +## Release + +> Ensure you have the appropriate credentials and permissions to publish to PyPI. + +1. Run the following commands for publishing the packages to PyPI: + + > [!TIP] + > Consider using the `--dry-run` flag to check if everything is correct before publishing. + + > For a single package release (e.g. patching `openbb-core`), the following steps are not required since the package can be published manually. + + 1. To publish `openbb-core` run: `python build/pypi/openbb_platform/publish.py --core` + 2. To publish **ALL** extensions run: `python build/pypi/openbb_platform/publish.py --extensions` + 3. To publish `openbb` (the main package) run: `python build/pypi/openbb_platform/publish.py --openbb` + > [!TIP] + > Note that, in order for packages to pick up the latest versions of dependencies, it is advised to clear the local cache of the dependencies: we can do that with `pip cache purge` and `poetry cache clear pypi --all`. Sometimes there might be some delay in the PyPI API, so it might be necessary to wait a few minutes for pip to pick the latest versions. + +2. Publish the CLI + + 2.1. Bump `openbb` dependency on `cli/pyproject.toml` to the latest version + + 2.2. Run `poetry publish --build` from `cli` + +3. Regenerate assets for external use by running `python assets/scripts/generate_extension_data.py`. +4. Merge `release/-` to the `main` branch. +5. Run `Deploy to GitHub Pages` action in [openbb-docs](https://github.com/OpenBB-finance/openbb-docs/actions) to update the documentation website. Go to [docs.openbb.co](https://docs.openbb.co) to see the changes. + +## Post-release + +1. Install the packages on Google Colaboratory via PyPi and test to check if everything is working as expected. +2. Install the packages in a new environment locally via PyPi and test to check if everything is working as expected. +3. Open a new PR with the `release/-` branch pointing to the `develop` branch. +4. Merge the `release/-` branch to the `develop` branch. +5. If any bugs are encountered, create a new branch - `hotfix` for `main` and `bugfix` for `develop` and merge them accordingly. + +### Generate the changelog + +1. Run the changelog automation by using the "release_drafter" GitHub action and input the number of the last release PR (not this one!). +2. Edit and make the changelog live on the repository. +3. Paste it in the platform-release-changelog Slack channel. diff --git a/build/pypi/openbb_platform/nightly.py b/build/pypi/openbb_platform/nightly.py new file mode 100644 index 0000000000000000000000000000000000000000..c8e610365bf7f2806a20d10c19f4ffe25966fd06 --- /dev/null +++ b/build/pypi/openbb_platform/nightly.py @@ -0,0 +1,86 @@ +import subprocess +import sys +from pathlib import Path +from typing import Any, Dict + +import toml + +PLATFORM_PATH = Path(__file__).parent.parent.parent.parent.resolve() / "openbb_platform" +PYPROJECT = PLATFORM_PATH / "pyproject.toml" + +SUB_PACKAGES = {} +DEPENDENCIES: Dict[str, Any] = {} +PLUGINS: Dict[str, Dict] = { + "openbb_core_extension": {}, + "openbb_provider_extension": {}, + "openbb_obbject_extension": {}, +} +CMD = [sys.executable, "-m", "poetry", "build"] + + +PYPROJECT_TOML = toml.load(PYPROJECT) +POETRY_DICT: Dict[str, dict] = PYPROJECT_TOML["tool"]["poetry"] +POETRY_DICT.pop("extras", None) + + +original_pyproject = PYPROJECT.read_text() + + +def gather_metadata(sub_path: str): + """Gather metadata from the pyproject.toml files. + + Parameters + ---------- + sub_path : str + The path to the sub packages. + """ + for path in PLATFORM_PATH.rglob(f"{sub_path}/**/pyproject.toml"): + pyproject_toml = toml.load(path) + poetry_dict: Dict[str, dict] = pyproject_toml["tool"]["poetry"] + package_name = poetry_dict["packages"][0]["include"] + + for extension in list(PLUGINS.keys()): + PLUGINS[extension].update(poetry_dict.get("plugins", {}).get(extension, {})) + + DEPENDENCIES.update(pyproject_toml["tool"]["poetry"]["dependencies"]) + SUB_PACKAGES[package_name] = path.relative_to(PLATFORM_PATH).parent.as_posix() + + +def build(): + """Build the Platform package.""" + for sub_path in ["core", "providers", "extensions", "obbject_extensions"]: + gather_metadata(sub_path) + + # need to pop these from the dependencies + DEPENDENCIES.pop("openbb-core", None) + + # add the sub packages + for package_name, path in SUB_PACKAGES.items(): + POETRY_DICT["packages"].append({"include": package_name, "from": f"./{path}"}) + + # add the plugins extensions + for extension, plugins in PLUGINS.items(): + POETRY_DICT.setdefault("plugins", {}).setdefault(extension, {}).update(plugins) + + # update the dependencies and platform poetry dict + POETRY_DICT["dependencies"] = DEPENDENCIES + PYPROJECT_TOML["tool"]["poetry"] = POETRY_DICT + + temp_pyproject = toml.dumps(PYPROJECT_TOML) + + try: + with open(PYPROJECT, "w", encoding="utf-8", newline="\n") as f: + f.write(temp_pyproject) + + subprocess.run(CMD, cwd=PLATFORM_PATH, check=True) # noqa: S603,PLW1510 + except (Exception, KeyboardInterrupt) as e: + print(e) # noqa: T201 + print("Restoring pyproject.toml") # noqa: T201 + + # we restore the original pyproject.toml + with open(PYPROJECT, "w", encoding="utf-8", newline="\n") as f: + f.write(original_pyproject) + + +if __name__ == "__main__": + build() diff --git a/build/pypi/openbb_platform/publish.py b/build/pypi/openbb_platform/publish.py new file mode 100644 index 0000000000000000000000000000000000000000..7e1df02faea92a5377706f10e927b98ad77b6380 --- /dev/null +++ b/build/pypi/openbb_platform/publish.py @@ -0,0 +1,239 @@ +"""Publish the OpenBB Platform to PyPi.""" + +import argparse +import logging +import sys +from functools import partial +from pathlib import Path +from subprocess import PIPE, run +from typing import Literal + +logger = logging.getLogger(__name__) +logger.setLevel(logging.INFO) +console = logging.StreamHandler() +logger.addHandler(console) +formatter = logging.Formatter("[%(levelname)s] %(message)s") +console.setFormatter(formatter) + +DIR_PLATFORM = Path(__file__).parent.parent.parent.parent.resolve() / "openbb_platform" +DIR_CORE = ["core"] +DIR_EXTENSIONS = ["extensions", "providers", "obbject_extensions"] + + +def parse_args(): + parser = argparse.ArgumentParser( + description="Publish OpenBB Platform to PyPi with optional core or extensions flag." + ) + parser.add_argument( + "-c", "--core", action="store_true", help="Publish core packages.", dest="core" + ) + parser.add_argument( + "-e", + "--extensions", + action="store_true", + help="Publish extension packages, such as openbb-equity or openbb-fmp.", + dest="extensions", + ) + parser.add_argument( + "-o", + "--openbb", + action="store_true", + help="Publish openbb package.", + dest="openbb", + ) + parser.add_argument( + "--dry-run", + action="store_true", + help="Run the commands without actually publishing.", + default=False, + dest="dry_run", + ) + parser.add_argument( + "-v", + "--verbose", + action="store_true", + help="Run the tool in verbose mode.", + default=False, + dest="verbose", + ) + parser.add_argument( + "-y", + "--yes", + action="store_true", + help="Answer input questions.", + default=False, + dest="yes", + ) + parser.add_argument( + "--semver", + help="Semantic version.", + default="patch", + choices=["patch", "minor", "major", "none"], + dest="semver", + ) + return parser.parse_args() + + +def publish( + dry_run: bool = False, + core: bool = False, + extensions: bool = False, + openbb: bool = False, + verbose: bool = False, + semver: Literal["patch", "minor", "major", "none"] = "patch", +): + """Publish the Platform to PyPi with optional core or extensions.""" + package_directories = [] + if core: + package_directories.extend(DIR_CORE) + if extensions: + package_directories.extend(DIR_EXTENSIONS) + + partial_run = partial( + run, + check=True, + stdout=None if verbose else PIPE, + stderr=None if verbose else PIPE, + ) + + for _dir in package_directories: + is_extension = _dir in DIR_EXTENSIONS + paths = [ + p + for p in sorted(DIR_PLATFORM.rglob(f"{_dir}/**/pyproject.toml")) + if "devtools" not in str(p) + ] + total = len(paths) + logger.info("~~~ /%s ~~~", _dir) + for i, path in enumerate(paths): + logger.info( + "๐Ÿš€ (%s/%s) Publishing openbb-%s...", + i + 1, + total, + path.parent.stem.replace("_", "-"), + ) + try: + # Update openbb-core to latest in each pyproject.toml + if is_extension: + partial_run( + [ + sys.executable, + "-m", + "poetry", + "add", + "openbb-core=latest", + "--lock", + ], + cwd=path.parent, + ) + # Bump pyproject.toml version + if semver != "none": + partial_run( + [sys.executable, "-m", "poetry", "version", semver], + cwd=path.parent, + ) + # Publish (if not dry running) + if not dry_run: + partial_run( + [ + sys.executable, + "-m", + "poetry", + "publish", + "--build", + ], + cwd=path.parent, + ) + logger.info("โœ… Success") + except Exception as e: + logger.error("โŒ Failed to publish %s:\n\n%s", path.parent.stem, e) + + if openbb: + STEPS = 7 + logger.info("~~~ /openbb ~~~") + logger.info("๐Ÿงฉ (1/%s) Installing poetry-plugin-up...", STEPS) + partial_run( + ["pip", "install", "poetry-plugin-up"], + cwd=DIR_PLATFORM, + ) + logger.info("โซ (2/%s) Updating openbb pyproject.toml...", STEPS) + partial_run( + [sys.executable, "-m", "poetry", "up", "--latest"], + cwd=DIR_PLATFORM, + ) + logger.info("๐Ÿ”’ (3/%s) Writing openbb poetry.lock...", STEPS) + partial_run( + [sys.executable, "-m", "poetry", "up", "--latest"], + cwd=DIR_PLATFORM, + ) + logger.info("๐Ÿ“ (4/%s) Installing openbb from /%s...", STEPS, DIR_PLATFORM.stem) + partial_run( + ["pip", "install", "-U", "--editable", "."], + cwd=DIR_PLATFORM, + ) + logger.info("๐Ÿšง (5/%s) Building python interface...", STEPS) + result = run( + [sys.executable, "-c", "import openbb; openbb.build()"], # noqa: S603 + cwd=DIR_PLATFORM, + check=True, + capture_output=True, + text=True, + ) + if verbose: + logger.info("Captured result -> %s", result) + if result.stderr: + logger.error("โŒ stderr is not empty!") + raise Exception(result.stderr) + logger.info("๐Ÿงช (6/%s) Unit testing...", STEPS) + partial_run( + ["pytest", "tests", "-m", "not integration"], + cwd=DIR_PLATFORM, + ) + logger.info("๐Ÿšญ (7/%s) Smoke testing...", STEPS) + # TODO: Improve smoke test coverage here + result = run( # noqa: S603 + [ # noqa: S603 + sys.executable, + "-c", + "from openbb import obb; obb.equity.price.historical('AAPL', provider='yfinance')", + ], + cwd=DIR_PLATFORM, + check=True, + capture_output=True, + text=True, + ) + if verbose: + logger.info("Captured result -> %s", result) + if result.stderr: + logger.error("โŒ stderr is not empty!") + raise Exception(result.stderr) + logger.info("๐Ÿ‘ Great success! ๐Ÿ‘") + logger.info( + "Confirm any files changed and run `poetry publish --build` from /openbb_platform" + ) + + +if __name__ == "__main__": + msg = ( + "\nYou are about to publish a new version of OpenBB Platform to PyPI." + + "\n\nPlease ensure you've read the PUBLISH.md file and double check with " + + "`poetry config --list` if you're publishing to PyPI or TestPyPI." + ) + args = parse_args() + if not args.dry_run: + msg += "\n\n๐Ÿ›‘ You are NOT using the --dry-run flag!" + res = "y" if args.yes else input(f"{msg}\n\nDo you want to continue? [y/N] ") + print("") # noqa: T201 + if res.lower() == "y": + logger.info("Process started. Press Ctrl+C to abort.") + try: + publish( + dry_run=args.dry_run, + core=args.core, + extensions=args.extensions, + openbb=args.openbb, + verbose=args.verbose, + semver=args.semver, + ) + except KeyboardInterrupt: + sys.exit(1)