PyDuckling
Copyright © 2020– Treble.ai
Overview
This package provides native bindings for Facebook's Duckling in Python. This package supports all dimensions and languages available on the original library, and it does not require to spawn a Haskell server and does not use HTTP to call the Duckling API.
Note: This package is completely Haskell-less
Installing
To install pyduckling, you can use both conda and pip package managers:
# Using pip
pip install pyduckling-native
# Using conda
conda install pyduckling -c treble-ai
Notes: Right now, we only provide package distributions for Linux (x86_64). We will provide Windows and Mac distributions on the next release
Dependencies
To compile pyduckling, you will require the latest nightly release of Rust, alongside Cargo. Also, it requires a Python distribution with its corresponding development headers. Finally, this project depends on the following Cargo crates:
- PyO3: Library used to produce Python bindings from Rust code.
- Maturin: Build system to build and publish Rust-based Python packages
Additionally, this package depends on Duckling-FFI, used to compile the native interface to Duckling on Haskell. In order to compile Duckling-FFI, you will require the Stack Haskell manager.
Installing locally
Besides Rust and Stack, you will require the latest version of maturin installed to compile this project locally:
pip install maturin toml
First, you will need to compile Duckling-FFI in order to produce the shared library libducklingffi, to do so, you can use the git submodule found at the root of this repository:
cd duckling-ffi
stack build
Then, you will need to move the resulting binary libducklingffi.so to the ext_lib folder:
cp duckling-ffi/libducklingffi.so ext_lib
After completing this procedure, it is possible to execute the following command to compile pyduckling:
maturin develop
In order to produce wheels, maturin build can be used instead. This project supports PEP517, thus pip can be used to install this package as well:
pip install -U .
Running tests
We use pytest to run tests as it follows (after calling maturin develop):
pytest -v duckling/tests
Package usage
PyDuckling provides access to the parsing capabilities of Duckling used to extract structured data from text.
# Core imports
from duckling import (load_time_zones, parse_ref_time,
parse_lang, default_locale_lang, parse_locale,
parse_dimensions, parse, Context)
# Load reference time for time parsing
time_zones = load_time_zones("/usr/share/zoneinfo")
bog_now = pendulum.now('America/Bogota').replace(microsecond=0)
ref_time = parse_ref_time(
time_zones, 'America/Bogota', bog_now.int_timestamp)
# Load language/locale information
lang_es = parse_lang('ES')
default_locale = default_locale_lang(lang_es)
locale = parse_locale('ES_CO', default_locale)
# Create parsing context with time and language information
context = Context(ref_time, locale)
# Define dimensions to look-up for
valid_dimensions = ["amount-of-money", "credit-card-number", "distance",
"duration", "email", "number", "ordinal",
"phone-number", "quantity", "temperature",
"time", "time-grain", "url", "volume"]
# Parse dimensions to use
output_dims = parse_dimensions(valid_dimensions)
# Parse a phrase
result = parse('En dos semanas', context, dims, False)
This wrapper allows access to all the dimensions and languages available on Duckling:
| Dimension | Example input | Example value output |
|---|---|---|
amount-of-money |
"42€" | {"value":42,"type":"value","unit":"EUR"} |
credit-card-number |
"4111-1111-1111-1111" | {"value":"4111111111111111","issuer":"visa"} |
distance |
"6 miles" | {"value":6,"type":"value","unit":"mile"} |
duration |
"3 mins" | {"value":3,"minute":3,"unit":"minute","normalized":{"value":180,"unit":"second"}} |
email |
"duckling-team@fb.com" | {"value":"duckling-team@fb.com"} |
number |
"eighty eight" | {"value":88,"type":"value"} |
ordinal |
"33rd" | {"value":33,"type":"value"} |
phone-number |
"+1 (650) 123-4567" | {"value":"(+1) 6501234567"} |
quantity |
"3 cups of sugar" | {"value":3,"type":"value","product":"sugar","unit":"cup"} |
temperature |
"80F" | {"value":80,"type":"value","unit":"fahrenheit"} |
time |
"today at 9am" | {"values":[{"value":"2016-12-14T09:00:00.000-08:00","grain":"hour","type":"value"}],"value":"2016-12-14T09:00:00.000-08:00","grain":"hour","type":"value"} |
url |
"https://api.wit.ai/message?q=hi" | {"value":"https://api.wit.ai/message?q=hi","domain":"api.wit.ai"} |
volume |
"4 gallons" | {"value":4,"type":"value","unit":"gallon"} |
Changelog
Please see our CHANGELOG file to learn more about our new features and improvements.
Contribution guidelines
We follow PEP8 and PEP257 for pure python packages and Rust to compile extensions. We use MyPy type annotations for all functions and classes declared on this package. Feel free to send a PR or create an issue if you have any problem/question.
Metadata
Release files for pyduckling-native 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyduckling-native-0.1.0.tar.gz | 23.4 kB | Without provenance | Details for pyduckling-native-0.1.0.tar.gz |
Built distributions (wheels)
Total release size: 234.1 MB
Release files / pyduckling-native-0.1.0.tar.gz
| Download URL | pyduckling-native-0.1.0.tar.gz |
|---|---|
| Size | 23.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9f3e93d6a905dfcf1b777f89d48579c3c820b335d4d8c9417bb9bb4c349cbbc1
|
|
BLAKE2b-256 checksum How to use checksums |
a47cf789f78d5b0c2081280880c03cb03c4d0f53b7ef5c58bf8b43e272ba9747
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1.post20200622 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.6
|
Release files / pyduckling_native-0.1.0-cp39-cp39-manylinux2014_x86_64.whl
| Download URL | pyduckling_native-0.1.0-cp39-cp39-manylinux2014_x86_64.whl |
|---|---|
| Size | 26.5 MB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
aeecc3f68b9e800181c0a4cfe1f388ee0911c9c81fb04a4cbcb393992e094c9f
|
|
BLAKE2b-256 checksum How to use checksums |
92b93394a60fbf4d3dad1b7e290db6298618f9bc0e7067776915bab971487adc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1.post20200622 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.6
|
Release files / pyduckling_native-0.1.0-cp38-cp38-manylinux2014_x86_64.whl
| Download URL | pyduckling_native-0.1.0-cp38-cp38-manylinux2014_x86_64.whl |
|---|---|
| Size | 26.5 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
5e5b6a78b90f757d3f6701a3a4a837443bbacac411c9f5e33f4a473dbb13841f
|
|
BLAKE2b-256 checksum How to use checksums |
979b986d611e257297fd35b9adff68ea2c67d6f4a406bb9c3a4b04b78df4bf7b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1.post20200622 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.6
|
Release files / pyduckling_native-0.1.0-cp38-cp38-macosx_10_15_x86_64.whl
| Download URL | pyduckling_native-0.1.0-cp38-cp38-macosx_10_15_x86_64.whl |
|---|---|
| Size | 25.4 MB |
| Tags | CPython 3.8 macOS 10.15+ x86-64 |
|
SHA-256 checksum How to use checksums |
6e996e2bc2eaf673b367c3380400d47207bfc12fdb9e15debbe790b240b91f8a
|
|
BLAKE2b-256 checksum How to use checksums |
cd7f90c8e598c135be0112841a1aa0649b6ba4f16403a86b1f1979df20101794
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1.post20200622 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.6
|
Release files / pyduckling_native-0.1.0-cp37-cp37m-manylinux2014_x86_64.whl
| Download URL | pyduckling_native-0.1.0-cp37-cp37m-manylinux2014_x86_64.whl |
|---|---|
| Size | 26.5 MB |
| Tags | CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
347b613de8878e208345f8dae6ccf5779f0f23eeea63ff4ad11b3ba303be52a3
|
|
BLAKE2b-256 checksum How to use checksums |
c4aeac7f5b66cce48b58a2562ca7bc035cffb418ad5477b350a3d170ff19bbc5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1.post20200622 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.6
|
Release files / pyduckling_native-0.1.0-cp37-cp37m-macosx_10_15_x86_64.whl
| Download URL | pyduckling_native-0.1.0-cp37-cp37m-macosx_10_15_x86_64.whl |
|---|---|
| Size | 25.4 MB |
| Tags | CPython 3.7 CPython 3.7 pymalloc macOS 10.15+ x86-64 |
|
SHA-256 checksum How to use checksums |
2d44ee0d04755532a5c06fc8c5cabe2a4b6120b571598d18e71c70c49064ba8b
|
|
BLAKE2b-256 checksum How to use checksums |
c56949e6018f0399cf81cde00b921520622a0c21ab2761e59d2cbb3cdda40b5c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1.post20200622 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.6
|
Release files / pyduckling_native-0.1.0-cp36-cp36m-manylinux2014_x86_64.whl
| Download URL | pyduckling_native-0.1.0-cp36-cp36m-manylinux2014_x86_64.whl |
|---|---|
| Size | 26.5 MB |
| Tags | CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
b579928da5902ff22f96d848307e25464a935f580bd68f87109748614fc2ad66
|
|
BLAKE2b-256 checksum How to use checksums |
a53fd302532aa689e9e98bf8dca447d6a022e8c73b0dbe8e0f7311531c65e52f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1.post20200622 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.6
|
Release files / pyduckling_native-0.1.0-cp36-cp36m-macosx_10_15_x86_64.whl
| Download URL | pyduckling_native-0.1.0-cp36-cp36m-macosx_10_15_x86_64.whl |
|---|---|
| Size | 25.4 MB |
| Tags | CPython 3.6 CPython 3.6 pymalloc macOS 10.15+ x86-64 |
|
SHA-256 checksum How to use checksums |
3e87a2fa810999912620cf90448f1ad28e158e17f1c5d6972468ea3aba84bf4d
|
|
BLAKE2b-256 checksum How to use checksums |
92c1a5c061cf24e6e6ae8471254340d472a3a4c3620bb1eae1a74e98fc7cbdca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1.post20200622 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.6
|
Release files / pyduckling_native-0.1.0-cp35-cp35m-manylinux2014_x86_64.whl
| Download URL | pyduckling_native-0.1.0-cp35-cp35m-manylinux2014_x86_64.whl |
|---|---|
| Size | 26.5 MB |
| Tags | CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
94362fc284d4784503e123efd8a78d4dc8047ca12811da75954d4bfffcdc6205
|
|
BLAKE2b-256 checksum How to use checksums |
c8db1d2df35623ae2dcbc9ce01823cc6c112988910452dfb9055ed09f8084786
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1.post20200622 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.6
|
Release files / pyduckling_native-0.1.0-cp35-cp35m-macosx_10_15_x86_64.whl
| Download URL | pyduckling_native-0.1.0-cp35-cp35m-macosx_10_15_x86_64.whl |
|---|---|
| Size | 25.4 MB |
| Tags | CPython 3.5 CPython 3.5 pymalloc macOS 10.15+ x86-64 |
|
SHA-256 checksum How to use checksums |
a9c262c6f33298eedaa75fa38bcfaec3dfc406355df05239dd8f424bb7f938c4
|
|
BLAKE2b-256 checksum How to use checksums |
b2b4f43061ff7dc52afe2b70c034c1acf1c33b1309283a11a0dd46d3707814d9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1.post20200622 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.6
|
Security for pyduckling-native 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.