SQL DB
Installation
Fetching from Databases supported by SqlAlchemy requires installing extra dependency.
pip install media-fetching[sql]
uv pip install media-fetching[sql]
Installing DB drivers
Depending on your DB you might need to install a specific DB driver for SqlAlchemy.
Usage
media-fetcher \
--source sqldb \
--sqldb.connection_string=sqlite:///media_results.db \
--sqldb.table=table_name
import media_fetching
from media_fetching.sources import sql
fetcher = media_fetching.MediaFetchingService(source='sqldb')
request = sql.SqlAlchemyQueryFetchingParameters(
connection_string='sqlite:///media_results.db',
table='table_name'
)
report = fetcher.fetch(request)
Reports can be written and processed. Learn more at garf.
Parameters
Mandatory
connection_string
- Database URL in SQLAlchemy format.table
- Name of a table in the database.
Optional
media_identifier
- column name in the table representing path to the media.media_name
- column name in the table representing name of the media.metrics
- column names of metrics to get from the table.segments
- column names of dimensions to get from the table.
media-fetcher \
--source sqldb \
--sqldb.connection-string=sqlite:///media_results.db \
--sqldb.table=table_name \
--sqldb.media-identifier=media_url \
--sqldb.media-name=media_name \
--sqldb.metrics=clicks,impressions \
--sqldb.segments=date
import media_fetching
from media_fetching.sources import sql
fetcher = media_fetching.MediaFetchingService(source='sqldb')
request = sql.SqlAlchemyQueryFetchingParameters(
connection_string='sqlite:///media_results.db',
table='table_name'
media_identifier='media_url',
media_name='media_name',
metrics=['clicks', 'impressions'],
segments=['date'],
)
report = fetcher.fetch(request)