fix: update outdated examples in openbb-apachebeam (#7286)

- examples/openbb-apachebeam/README.md: Fix test-run command to point to example tests directory, fix typos and grammar
- examples/openbb-apachebeam/requirements.txt: Add core 'openbb' dependency required by example
- examples/openbb-apachebeam/tests/test_obb_pipeline.py: Fix code formatting, fix 'Print nes' typo to 'Print news'

Fixes #7181

Co-authored-by: Murat Aslan <murataslan1@users.noreply.github.com>
Co-authored-by: Danglewood <85772166+deeleeramone@users.noreply.github.com>
This commit is contained in:
Murat Aslan
2026-01-28 03:08:10 +03:00
committed by GitHub
parent 8b2fc16f1d
commit fd236f806a
2 changed files with 28 additions and 18 deletions

View File

@@ -1,12 +1,13 @@
# OBB Dataflow Sample # OBB Dataflow Sample
This is a sample on how to invoke OBB fetchers in an Apache Beam pipeline. (GCP Dataflow is built on Apache Beam)
This is a sample how to invoke OBB fetchers in an Apache Beam pipeline. (GCP dataflow is build on Apache Beam)
Pre-requisites Pre-requisites
- You need to create a Conda environment (or a virtual env) using requirements.txt in this directory - You need to create a Conda environment (or a virtual env) using `requirements.txt` in this directory
- The script exercise 3 OBB endpoints, all of which require no credentials - The script exercises three OBB endpoints, all of which require no credentials
- Run the test from the main directory - Run the test from this directory:
python -m unittest .\tests\test_obb_pipeline.py cd examples/openbb-apachebeam
python -m unittest tests/test_obb_pipeline.py
The script will run a pipeline consisting of 3 task which will fetch AAPL quote, profile and news The script will run a pipeline consisting of three tasks which will fetch an AAPL quote, profile, and news.
This is just a very basic sample which can be used as building block to create more complex scenarios This is just a very basic sample which can be used as a building block to create more complex scenarios

View File

@@ -22,8 +22,8 @@ class AsyncProcess(beam.DoFn):
def process(self, element: str): def process(self, element: str):
return asyncio.run(self.fetch_data(element)) return asyncio.run(self.fetch_data(element))
class MyTestCase(unittest.TestCase):
class MyTestCase(unittest.TestCase):
def test_sample_pipeline(self): def test_sample_pipeline(self):
credentials = {} # Running OBB endpoints which do not require credentials credentials = {} # Running OBB endpoints which do not require credentials
@@ -31,17 +31,26 @@ class MyTestCase(unittest.TestCase):
ticker = 'AAPL' ticker = 'AAPL'
with TestPipeline(options=PipelineOptions()) as p: with TestPipeline(options=PipelineOptions()) as p:
quote = (p | 'Start Quote' >> beam.Create([ticker]) quote = (
p
| 'Start Quote' >> beam.Create([ticker])
| 'Run Quote' >> beam.ParDo(AsyncProcess(credentials, quote_fetcher)) | 'Run Quote' >> beam.ParDo(AsyncProcess(credentials, quote_fetcher))
| 'Print quote' >> debug_sink) | 'Print quote' >> debug_sink
)
profile = (p | 'Start Profile' >> beam.Create([ticker]) profile = (
p
| 'Start Profile' >> beam.Create([ticker])
| 'Run Profile' >> beam.ParDo(AsyncProcess(credentials, profile_fetcher)) | 'Run Profile' >> beam.ParDo(AsyncProcess(credentials, profile_fetcher))
| 'Print profile' >> debug_sink) | 'Print profile' >> debug_sink
)
news = (p | 'Start News' >> beam.Create([ticker]) news = (
p
| 'Start News' >> beam.Create([ticker])
| 'Run News' >> beam.ParDo(AsyncProcess(credentials, news_fetcher)) | 'Run News' >> beam.ParDo(AsyncProcess(credentials, news_fetcher))
| 'Print nes' >> debug_sink) | 'Print news' >> debug_sink
)
if __name__ == '__main__': if __name__ == '__main__':