Stores
ftmq
extends the statement based store implementation of nomenklatura
with more granular querying and aggregation possibilities.
Initialize a store
Get an initialized Store. The backend is inferred by the scheme of the store uri.
Example
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uri
|
PathLike | None
|
The store backend uri |
'memory:///'
|
catalog
|
Catalog | None
|
A |
None
|
dataset
|
Dataset | str | None
|
A |
None
|
linker
|
Resolver | str | None
|
A |
None
|
Returns:
Type | Description |
---|---|
Store
|
The initialized store. This is a cached object. |
Source code in ftmq/store/__init__.py
Supported backends
- in memory:
get_store("memory://")
- Redis (or kvrocks):
get_store("redis://localhost")
- LevelDB:
get_store("leveldb://data")
- Sql:
- sqlite:
get_store("sqlite:///data.db")
- postgresql:
get_store("postgresql://user:password@host/db")
- ...any other supported by
sqlalchemy
- sqlite:
- Clickhouse via
ftm-clickhouse
:get_store("clickhouse://localhost")
Read and query entities
Iterate through all the entities via Store.iterate
:
from ftmq.store import get_store
store = get_store("sqlite:///followthemoney.store")
proxies = store.iterate()
Filter entities with a Query
object using a store view:
from ftmq import Query
q = Query().where(dataset="my_dataset", schema="Person")
proxies = store.view(q)
Command line
Write entities to a store
Use the bulk writer:
Or the smart_write_proxies
shorthand, which uses the same bulk writer under the hood:
from ftmq.io import smart_write_proxies
smart_write_proxies("sqlite:///followthemoney.store", proxies)
Command line
If the input entities don't have a dataset
property, ensure a default dataset with the --store-dataset
parameter.