# Passing parameters to a python function via pycall that need to be in a dict form

**URL:** <https://discourse.julialang.org/t/passing-parameters-to-a-python-function-via-pycall-that-need-to-be-in-a-dict-form/84691>\
**Category:** New to Julia\
**Tags:** pycall, parser\
**Created:** [July 23, 2022, 11:54pm UTC](https://discourse.julialang.org/t/passing-parameters-to-a-python-function-via-pycall-that-need-to-be-in-a-dict-form/84691 "2022-07-23T23:54:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![conalbrown](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/conalbrown/32/30423_2.png) [@conalbrown](https://discourse.julialang.org/u/conalbrown)\
**Post date:** [July 23, 2022, 11:54pm UTC](https://discourse.julialang.org/t/passing-parameters-to-a-python-function-via-pycall-that-need-to-be-in-a-dict-form/84691/1 "2022-07-23T23:54:12Z")

</div>

I’m trying to use the Date Parser package from Python in a Pluto notebook. The example from the package documentation I am trying to replicate is this:  
parse(‘December 2015’, settings={‘STRICT\_PARSING’: True})

I can get the basic command to work by changing single quotes to double quotes for it to recognise the date string. I don’t know how to change the kwarg command settings={‘STRICT\_PARSING’: True}, which needs to be passed to the parse() command as a dict data type.

How do I convert this into something Python will understand?

My Pluto Notebook is below:

```julia-auto
Conda.add("dateparser")
dparser = pyimport("dateparser")
#Command in Python: parse('December 2015', settings={'STRICT_PARSING': True})
output = dparser.parse("December 2015")
output
2015-12-23T00:00:00

```

None of the following attempts worked:

```julia-auto
dparser.parse("December 2015", settings={"STRICT_PARSING": True})
dparser.parse("December 2015", settings=PyDict{"STRICT_PARSING": True})
dparser.parse("December 2015", settings=PyDict{"STRICT_PARSING": "True"})
py"""

"""
begin
	py"""
kwargs = {'STRICT_PARSING': True}
"""
	r = dparser.parse('December 2015', settings=py"kwargs"))
end

```

I am trying to process a long list of dates where sometimes the day, month and year is given, but other times just the year and the month and the year is given. I don’t think there is a similar option in Dates.jl to not parse incomplete dates - which is why I’ve turned to Python. In Python I will also be able to access the span command in the arrow package, which will help me to find the range of possible dates for when the day or month is not stated. Again, I haven’t found anything similar in Julia to do this.

The Date Parser function definition is:

## Basic Usage

The most straightforward way is to use the [dateparser.parse](https://dateparser.readthedocs.io/en/latest/introduction.html#dateparser.parse) function, that wraps around most of the functionality in the module.

`dateparser.` `parse` (_date\_string_, _date\_formats=None_, _languages=None_, _locales=None_, _region=None_, _settings=None_, _detect\_languages\_function=None_ )[[source]](https://dateparser.readthedocs.io/en/latest/_modules/dateparser.html#parse)

Parse date and time from given date string.

Parameters: \* **date\_string** ([_str_](https://docs.python.org/3/library/stdtypes.html#str)) – A string representing date and/or time in a recognizably valid format.

- **date\_formats** ([_list_](https://docs.python.org/3/library/stdtypes.html#list)) – A list of format strings using directives as given [here](https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior). The parser applies formats one by one, taking into account the detected languages/locales.
- **languages** ([_list_](https://docs.python.org/3/library/stdtypes.html#list)) – A list of language codes, e.g. [‘en’, ‘es’, ‘zh-Hant’]. If locales are not given, languages and region are used to construct locales for translation.
- **locales** ([_list_](https://docs.python.org/3/library/stdtypes.html#list)) – A list of locale codes, e.g. [‘fr-PF’, ‘qu-EC’, ‘af-NA’]. The parser uses only these locales to translate date string.
- **region** ([_str_](https://docs.python.org/3/library/stdtypes.html#str)) – A region code, e.g. ‘IN’, ‘001’, ‘NE’. If locales are not given, languages and region are used to construct locales for translation.
- **settings** ([_dict_](https://docs.python.org/3/library/stdtypes.html#dict)) – Configure customized behavior using settings defined in [`dateparser.conf.Settings`](https://dateparser.readthedocs.io/en/latest/dateparser.html#dateparser.conf.Settings).
- **detect\_languages\_function** (_function_) – A function for language detection that takes as input a string (the date\_string) and a confidence\_threshold, and returns a list of detected language codes. Note: this function is only used if `languages` and `locales` are not provided.  
Returns: Returns [`datetime`](https://docs.python.org/3/library/datetime.html#datetime.datetime) representing parsed date if successful, else returns None  
Return type: [`datetime`](https://docs.python.org/3/library/datetime.html#datetime.datetime).  
Raises: `ValueError`: Unknown Language, `TypeError`: Languages argument must be a list, `SettingValidationError`: A provided setting is not valid.

Thanks

---

<div class="post-metadata">

**Author:** ![icweaver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/icweaver/32/45764_2.png) [@icweaver](https://discourse.julialang.org/u/icweaver)\
**Post date:** [July 24, 2022, 12:56am UTC](https://discourse.julialang.org/t/passing-parameters-to-a-python-function-via-pycall-that-need-to-be-in-a-dict-form/84691/2 "2022-07-24T00:56:09Z")

</div>

I don’t think the examples you tried involving `PyDict{<...>}` are valid Julia syntax. I would just pass a `Dict` instead:

```julia
output = dparser.parse("December 2015"; settings=Dict("STRICT_PARSING" => true))

```

---

<div class="post-metadata">

**Author:** ![conalbrown](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/conalbrown/32/30423_2.png) [@conalbrown](https://discourse.julialang.org/u/conalbrown)\
**Post date:** [July 24, 2022, 9:16am UTC](https://discourse.julialang.org/t/passing-parameters-to-a-python-function-via-pycall-that-need-to-be-in-a-dict-form/84691/3 "2022-07-24T09:16:08Z")

</div>

Great, this worked! Sorry I’m very much a beginner and have not used a Dict() structure before.

---

<div class="post-metadata">

**Author:** ![icweaver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/icweaver/32/45764_2.png) [@icweaver](https://discourse.julialang.org/u/icweaver)\
**Post date:** [July 24, 2022, 5:25pm UTC](https://discourse.julialang.org/t/passing-parameters-to-a-python-function-via-pycall-that-need-to-be-in-a-dict-form/84691/4 "2022-07-24T17:25:43Z")

</div>

No worries! By the way, I had no idea that Dates.jl was so [permissive](https://github.com/JuliaLang/julia/issues/28090), that’s certainly good to know. It looks like this is on the horizon to be [addressed in 2.0](https://github.com/JuliaLang/julia/issues/43883)

On the python end of things, you may also want to check out [PythonCall.jl](https://github.com/cjdoris/PythonCall.jl)/[CondaPkg.jl](https://github.com/cjdoris/CondaPkg.jl). It’s a newer alternative to PyCall.jl/Conda.jl that is pretty nice to work with, even in Pluto notebooks

![image](https://global.discourse-cdn.com/julialang/original/3X/5/3/536bf9a22770bc0747003b6c72700e2eb5fe2522.png)

One of its main selling points for me is the use of project specific environments to avoid polluting your global
