ftmq.io
apply_datasets(proxies, *datasets, replace=False)
Apply datasets to a stream of proxies
Parameters:
Name | Type | Description | Default |
---|---|---|---|
proxies
|
Iterable[CE]
|
Iterable of |
required |
*datasets
|
Iterable[str]
|
One or more dataset names to apply |
()
|
replace
|
bool | None
|
Drop any other existing datasets |
False
|
Yields:
Type | Description |
---|---|
CEGenerator
|
The proxy stream with the datasets applied |
Source code in ftmq/io.py
smart_read_proxies(uri, mode=DEFAULT_MODE, serialize=True, query=None, **store_kwargs)
Stream proxies from an arbitrary source
Example
from ftmq import Query
from ftmq.io import smart_read_proxies
# remote file-like source
for proxy in smart_read_proxies("s3://data/entities.ftm.json"):
print(proxy.schema)
# multiple files
for proxy in smart_read_proxies("./1.json", "./2.json"):
print(proxy.schema)
# nomenklatura store
for proxy in smart_read_proxies("redis://localhost", dataset="default"):
print(proxy.schema)
# apply a query to sql storage
q = Query(dataset="my_dataset", schema="Person")
for proxy in smart_read_proxies("sqlite:///data/ftm.db", query=q):
print(proxy.schema)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uri
|
PathLike | Iterable[PathLike]
|
File-like uri or store uri or multile uris |
required |
mode
|
str | None
|
Open mode for file-like sources (default: |
DEFAULT_MODE
|
serialize
|
bool | None
|
Convert json data into |
True
|
query
|
Query | None
|
Filter |
None
|
**store_kwargs
|
Any
|
Pass through configuration to statement store |
{}
|
Yields:
Type | Description |
---|---|
CEGenerator
|
A stream of |
Source code in ftmq/io.py
smart_write_proxies(uri, proxies, mode='wb', serialize=False, **store_kwargs)
Write a stream of proxies (or data dicts) to an arbitrary target.
Example
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uri
|
PathLike
|
File-like uri or store uri |
required |
proxies
|
Iterable[CE | SDict]
|
Iterable of proxy data |
required |
mode
|
str | None
|
Open mode for file-like targets (default: |
'wb'
|
serialize
|
bool | None
|
Convert |
False
|
**store_kwargs
|
Any
|
Pass through configuration to statement store |
{}
|
Returns:
Type | Description |
---|---|
int
|
Number of written proxies |