1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00
Files
jc/docs/lib.md

167 lines
4.3 KiB
Markdown
Raw Normal View History

# Table of Contents
* [jc.lib](#jc.lib)
* [parse](#jc.lib.parse)
* [parser\_mod\_list](#jc.lib.parser_mod_list)
* [plugin\_parser\_mod\_list](#jc.lib.plugin_parser_mod_list)
2022-03-03 17:38:47 -08:00
* [standard\_parser\_mod\_list](#jc.lib.standard_parser_mod_list)
* [streaming\_parser\_mod\_list](#jc.lib.streaming_parser_mod_list)
* [parser\_info](#jc.lib.parser_info)
2022-01-26 15:54:36 -08:00
* [all\_parser\_info](#jc.lib.all_parser_info)
* [get\_help](#jc.lib.get_help)
2022-01-25 17:07:47 -08:00
<a id="jc.lib"></a>
# jc.lib
2022-01-19 22:20:36 -08:00
2022-03-04 13:27:39 -08:00
jc - JSON Convert
2022-01-19 22:20:36 -08:00
JC lib module
2022-01-25 17:07:47 -08:00
<a id="jc.lib.parse"></a>
2022-03-05 12:15:14 -08:00
### parse
2022-01-19 22:20:36 -08:00
```python
2022-03-04 13:27:39 -08:00
def parse(parser_mod_name: str,
data: Union[str, Iterable[str]],
quiet: bool = False,
raw: bool = False,
ignore_exceptions: bool = None,
**kwargs) -> Union[Dict, List[Dict], Iterator[Dict]]
2022-01-19 22:20:36 -08:00
```
Parse the string data using the supplied parser module.
This function provides a high-level API to simplify parser use. This
function will call built-in parsers and custom plugin parsers.
2022-01-25 18:03:34 -08:00
Example:
>>> import jc
>>> jc.parse('date', 'Tue Jan 18 10:23:07 PST 2022')
{'year': 2022, 'month': 'Jan', 'month_num': 1, 'day'...}
2022-03-04 08:57:11 -08:00
To get a list of available parser module names, use `parser_mod_list()`.
2022-01-25 18:03:34 -08:00
You can also use the lower-level parser modules directly:
>>> import jc.parsers.date
>>> jc.parsers.date.parse('Tue Jan 18 10:23:07 PST 2022')
Though, accessing plugin parsers directly is a bit more cumbersome, so
this higher-level API is recommended. Here is how you can access plugin
parsers without this API:
>>> import os
>>> import sys
>>> import jc.appdirs
>>> data_dir = jc.appdirs.user_data_dir('jc', 'jc')
>>> local_parsers_dir = os.path.join(data_dir, 'jcparsers')
>>> sys.path.append(local_parsers_dir)
>>> import my_custom_parser
>>> my_custom_parser.parse('command_data')
Parameters:
parser_mod_name: (string) name of the parser module. This
function will accept module_name,
cli-name, and --argument-name
variants of the module name.
data: (string or data to parse (string for normal
iterator) parsers, iterator of strings for
streaming parsers)
raw: (boolean) output preprocessed JSON if True
quiet: (boolean) suppress warning messages if True
ignore_exceptions: (boolean) ignore parsing exceptions if True
(streaming parsers only)
Returns:
Standard Parsers: Dictionary or List of Dictionaries
Streaming Parsers: Generator Object containing Dictionaries
2022-01-25 17:07:47 -08:00
<a id="jc.lib.parser_mod_list"></a>
2022-03-05 12:15:14 -08:00
### parser\_mod\_list
2022-01-19 22:20:36 -08:00
2022-01-25 17:07:47 -08:00
```python
def parser_mod_list() -> List[str]
```
2022-01-19 22:20:36 -08:00
2022-01-25 17:07:47 -08:00
Returns a list of all available parser module names.
2022-01-19 22:20:36 -08:00
2022-01-25 17:07:47 -08:00
<a id="jc.lib.plugin_parser_mod_list"></a>
2022-01-19 22:20:36 -08:00
2022-03-05 12:15:14 -08:00
### plugin\_parser\_mod\_list
2022-01-19 22:20:36 -08:00
2022-01-25 17:07:47 -08:00
```python
def plugin_parser_mod_list() -> List[str]
```
2022-01-19 22:20:36 -08:00
2022-01-25 17:07:47 -08:00
Returns a list of plugin parser module names. This function is a
subset of `parser_mod_list()`.
2022-01-19 22:20:36 -08:00
2022-03-03 17:38:47 -08:00
<a id="jc.lib.standard_parser_mod_list"></a>
2022-03-05 12:15:14 -08:00
### standard\_parser\_mod\_list
2022-03-03 17:38:47 -08:00
```python
def standard_parser_mod_list() -> List[str]
```
Returns a list of standard parser module names. This function is a
subset of `parser_mod_list()` and does not contain any streaming
parsers.
<a id="jc.lib.streaming_parser_mod_list"></a>
2022-03-05 12:15:14 -08:00
### streaming\_parser\_mod\_list
2022-03-03 17:38:47 -08:00
```python
def streaming_parser_mod_list() -> List[str]
```
Returns a list of streaming parser module names. This function is a
subset of `parser_mod_list()`.
2022-01-25 17:07:47 -08:00
<a id="jc.lib.parser_info"></a>
2022-01-19 22:24:59 -08:00
2022-03-05 12:15:14 -08:00
### parser\_info
2022-01-19 22:20:36 -08:00
2022-01-25 17:07:47 -08:00
```python
2022-02-01 18:33:07 -08:00
def parser_info(parser_mod_name: str) -> Dict
2022-01-25 17:07:47 -08:00
```
2022-01-19 22:20:36 -08:00
2022-01-25 17:07:47 -08:00
Returns a dictionary that includes the module metadata.
2022-01-19 22:20:36 -08:00
2022-01-26 16:34:23 -08:00
This function will accept **module_name**, **cli-name**, and
**--argument-name** variants of the module name string.
2022-01-19 22:20:36 -08:00
2022-01-26 15:54:36 -08:00
<a id="jc.lib.all_parser_info"></a>
2022-03-05 12:15:14 -08:00
### all\_parser\_info
2022-01-26 15:54:36 -08:00
```python
2022-02-01 18:33:07 -08:00
def all_parser_info() -> List[Dict]
2022-01-26 15:54:36 -08:00
```
2022-02-01 17:57:12 -08:00
Returns a list of dictionaries that includes metadata for all modules.
2022-01-26 15:54:36 -08:00
2022-01-25 17:07:47 -08:00
<a id="jc.lib.get_help"></a>
2022-01-19 22:20:36 -08:00
2022-03-05 12:15:14 -08:00
### get\_help
2022-01-19 22:20:36 -08:00
```python
2022-01-25 17:07:47 -08:00
def get_help(parser_mod_name: str) -> None
2022-01-19 22:20:36 -08:00
```
2022-01-20 07:49:45 -08:00
2022-01-25 17:07:47 -08:00
Show help screen for the selected parser.
2022-01-20 07:49:45 -08:00
2022-01-26 16:34:23 -08:00
This function will accept **module_name**, **cli-name**, and
**--argument-name** variants of the module name string.
2022-01-19 22:20:36 -08:00