Datasource API¶
API for working with the Datasource type.
Import this module like this:
from sympathy.api import datasource
Class datasource.File
¶
- class sympathy.typeutils.datasource.File(filename: Optional[str] = None, mode: str = 'r', **kwargs)[source]¶
Datasource covers the case of specifying data resources and supports four different formats: File (local file), Database (ODBC), Database SQLAlchemy and URL (for example, HTTP request).
Any node port with the Datasource type will produce an object of this kind.
Formats:
- File:
Absolute filename to a local file.
- Database (ODBC):
Connection string for use with a ODBC database.
- Database SQLAlchemy:
Engine connection string for use with SQLAlchemy.
- URL:
Arbitrary URL, can support file or http(s) schemes. In addition to the URL itself this format format allows storage of a separate environment dictionary, for example, to use as HTTP headers.
- decode_path()[source]¶
Return the path.
In a file data source this corresponds to the path of a file. In a data base data source this corresponds to a connection string. That can be used for accessing the data base. Returns None if path hasn’t been set.
Changed in version 1.2.5: Return None instead of raising KeyError if path hasn’t been set.
- decode_type()[source]¶
Return the type of this data source.
It can be either
'FILE'
or'DATABASE'
. Returns None if type hasn’t been set.Changed in version 1.2.5: Return None instead of raising KeyError if type hasn’t been set.
- encode(datasource_dict)[source]¶
Store the info from datasource_dict in this datasource.
- Parameters
datasource_dict – should be a dictionary of the same format that you get from
to_file_dict()
orto_database_dict()
.
- encode_path(filename)[source]¶
Store a path to a file in this datasource.
- Parameters
filename – should be a string containing the path. Can be relative or absolute.
- classmethod from_filename(filename)[source]¶
Return new file type datasource constructed from filename.
- names(kind=None, fields=None, **kwargs)[source]¶
Return a formatted list with a name and type of the data. columns.
- static to_file_dict(fq_filename)[source]¶
Create a dictionary to be used for creating a file data source.
You usually want to use the convenience method
encode_path()
instead of calling this method directly.