Skip to main content

Rust-based Python wrapper for duckling library in Haskell.

Project description

PyDuckling

Project License - MIT pypi version Downloads PyPI status Linux Tests

Copyright © 2020– Treble.ai

ℹ️ This is a fork of the original pyduckling-native library. There are differences to the original:

  • Build against the latest version of Duckling
  • Supported Python versions range from 3.8 to 3.14
  • x86_64 Linux only, but contributions welcome if you dare to take on the challenge

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.

ℹ️ 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-phihos

ℹ️ Right now, we only provide package distributions for Linux (x86_64).

Version Matrix

The following table shows which PyDuckling version corresponds to which Duckling version

PyDuckling Duckling
0.2.0 v0.2.0.0 (commit 7520daa)
0.3.0 v0.2.0.0 (commit 7520daa)

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)
# Install with pip install pendulum
import pendulum

# 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, output_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"}

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

Via Docker

The only thing you need is a running Docker daemon and permission to run docker build and docker run. Then just run

./build.sh

All build dependencies are already installed in container images. The build script will get them and start containers for building the Haskell lib and the Python lib. The directories .cache, duckling-ffi/.stack-work and target will appear. The first two are for accelerating future builds and the last one will contain your final build result.

After the build.sh completed successfully, you can find wheel files (binary distributions of the library) inside target/wheels. The Python version (e.g. Python 3.11 = cp311), the libc variant (manylinux or musllinux, if you are unsure you probably need manylinux) and the CPU architecture (currently only x86_64) are encoded in the file name. Just pick the file matching to your system and install it with:

pip install -U target/wheels/<myfile>.whl

Manually

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.a to the ext_lib folder:

cp duckling-ffi/libducklingffi.a 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

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyduckling_native_phihos-0.3.0-cp314-cp314-musllinux_1_2_x86_64.whl (12.1 MB view details)

Uploaded CPython 3.14musllinux: musl 1.2+ x86-64

pyduckling_native_phihos-0.3.0-cp314-cp314-manylinux_2_28_x86_64.whl (12.1 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64

pyduckling_native_phihos-0.3.0-cp313-cp313-musllinux_1_2_x86_64.whl (12.1 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

pyduckling_native_phihos-0.3.0-cp313-cp313-manylinux_2_28_x86_64.whl (12.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

pyduckling_native_phihos-0.3.0-cp312-cp312-musllinux_1_2_x86_64.whl (12.1 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

pyduckling_native_phihos-0.3.0-cp312-cp312-manylinux_2_28_x86_64.whl (12.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

pyduckling_native_phihos-0.3.0-cp311-cp311-musllinux_1_2_x86_64.whl (12.1 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

pyduckling_native_phihos-0.3.0-cp311-cp311-manylinux_2_28_x86_64.whl (12.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

pyduckling_native_phihos-0.3.0-cp310-cp310-musllinux_1_2_x86_64.whl (12.1 MB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

pyduckling_native_phihos-0.3.0-cp310-cp310-manylinux_2_28_x86_64.whl (12.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

pyduckling_native_phihos-0.3.0-cp39-cp39-musllinux_1_2_x86_64.whl (12.1 MB view details)

Uploaded CPython 3.9musllinux: musl 1.2+ x86-64

pyduckling_native_phihos-0.3.0-cp39-cp39-manylinux_2_28_x86_64.whl (12.1 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ x86-64

pyduckling_native_phihos-0.3.0-cp38-cp38-musllinux_1_2_x86_64.whl (12.1 MB view details)

Uploaded CPython 3.8musllinux: musl 1.2+ x86-64

pyduckling_native_phihos-0.3.0-cp38-cp38-manylinux_2_28_x86_64.whl (12.1 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.28+ x86-64

File details

Details for the file pyduckling_native_phihos-0.3.0-cp314-cp314-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.3.0-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 4385487088676c1f56eb804810a4615941b7c40b89a9e81573041737b535906e
MD5 5c4e87f54c09c1056c9994c1d71526fb
BLAKE2b-256 6a6991213860de28de852007dd64fb241460542921f96b8621dd1ccca19f2666

See more details on using hashes here.

File details

Details for the file pyduckling_native_phihos-0.3.0-cp314-cp314-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.3.0-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 22d991e735f23501becbf0bca3afa05bf17a9e2e8a4826abdf5b834e4ca43fbe
MD5 e066545446d8f51c8a2d0390ff2bdacc
BLAKE2b-256 4d505d19d6820b0ac3affc8da3347ce01ef9980518a90a3d2dc36248a89a7dd1

See more details on using hashes here.

File details

Details for the file pyduckling_native_phihos-0.3.0-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.3.0-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 0aa8cad541ce472d1e5661fc8aadd280a631d509d0991da0d3559a4c2a4b68ee
MD5 d2e7e471eb8b67029b762980f5a3f2e4
BLAKE2b-256 6fa2a458ff1cfb1fe85564c82bb48c98fd672cf07df3c78bfb5c71bad4aec919

See more details on using hashes here.

File details

Details for the file pyduckling_native_phihos-0.3.0-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.3.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 18b41f03d92cef7e2b97203872906cdcc1bd566d9e01e93032f73676c5b6e113
MD5 e9d047c24b620d6a4e305bbe2e69aba2
BLAKE2b-256 5ea7010a37a00d784a62ecd3877402d5b32dc6bfc535cf6fa23183d2b2d736c0

See more details on using hashes here.

File details

Details for the file pyduckling_native_phihos-0.3.0-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.3.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5c8d6aac91c6f6da7dbe0ba33939eb91974e6596fa783c1ce0bb9429dd2cc5f7
MD5 662059e4fa2c1f56b460fd4dd1b6fb62
BLAKE2b-256 54267f1dc1a53f17acbb5ff60df51787e8e551d9a130c6967f41e9295401149d

See more details on using hashes here.

File details

Details for the file pyduckling_native_phihos-0.3.0-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.3.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 18e7c7dd8dee77510c0369f640ab21d1304f3c9ace71cb6416d135129db1e3c1
MD5 d5be9a03f49bec5b3a64c78fe14e3c2a
BLAKE2b-256 24a489bdc4e81fa4d3302dd50c728bfbfb1c75990c2f630ac51c0c4a0f7b6f9b

See more details on using hashes here.

File details

Details for the file pyduckling_native_phihos-0.3.0-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.3.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 914181ee50492cf130e6dfdf362c0521592cd49bbb7b54b445cac5ee843b7000
MD5 c92c5d1ddeab92980024fa69ffe4f444
BLAKE2b-256 a91d6ce19c9f58ff2f724c8c56a9ab1295ff299943c1f0ed02d4192e6c69b81a

See more details on using hashes here.

File details

Details for the file pyduckling_native_phihos-0.3.0-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.3.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 22f08a114370223edb55fee7c0164e39c2bbf28f3f5cb910234158d93dd5c1b5
MD5 35967cf42d003414bda7114304c37024
BLAKE2b-256 3a92dc5f48cc71b7561e2c1f75e68e2d0e3230dc6ed031980080067b228c91f7

See more details on using hashes here.

File details

Details for the file pyduckling_native_phihos-0.3.0-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.3.0-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e7f6524ad54872f31e00dcaf65cdcfee8f978affaf08a9dcb5f1bec707a99394
MD5 58503df14d5740a522e18d9101a53337
BLAKE2b-256 9f4ca22b87f3be94c084ee9a59386311e93d82140be757f03a3cce95fa44ccd0

See more details on using hashes here.

File details

Details for the file pyduckling_native_phihos-0.3.0-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.3.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7e4ce0e5c0fb594ecb7e8d44bfcae1886d1e1a957f7fe28b1785a68f3882ed65
MD5 4f794eb4da23712f6c900d2ac4d2e3e2
BLAKE2b-256 b1b587f5ca047698fc3d0792a315fbf39c62188672a8689a88b5fb7fe130e812

See more details on using hashes here.

File details

Details for the file pyduckling_native_phihos-0.3.0-cp39-cp39-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.3.0-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 6feada0cf10ae1d9695b34f673e1e0b12a91f2992bbbf4f03bfc377b38d2b277
MD5 cea027ae45b06d3084fe4540007e5260
BLAKE2b-256 256d12da7f0ff9ae2dea6b8b141531121dde482f6e612c70f126fd0a23473695

See more details on using hashes here.

File details

Details for the file pyduckling_native_phihos-0.3.0-cp39-cp39-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.3.0-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 63f750530b10c72d84d4e0db74c497d707041a0918ed35cdd672fbaafcd9906e
MD5 da7b4b32cfcf136bed319fc84e126fcd
BLAKE2b-256 6f24169a0388155b43cc59321dec2c5f5bbef4de4a2f6dcdd5e0cbefdde7e98e

See more details on using hashes here.

File details

Details for the file pyduckling_native_phihos-0.3.0-cp38-cp38-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.3.0-cp38-cp38-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 944443e6a71f2717859dd3def11542111e019499f2333bcc21ab8a458b27b402
MD5 aa7e4dcf68ca57b6ea0c066ec0873cf1
BLAKE2b-256 3b14e0eae01a73bb5757f72ea1ed5dede95dae7a7c1f9f3c91bdd804e44ee5a5

See more details on using hashes here.

File details

Details for the file pyduckling_native_phihos-0.3.0-cp38-cp38-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.3.0-cp38-cp38-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1c9fbbc2d7bf96a1ab4865a255b193de5a37fc9558b84043f878e0fcbf596169
MD5 eb350bd2d2bba48022a6a53f2c71c9e2
BLAKE2b-256 535417cd0892d76b8ac203bb6287fc82cae89c00d65572c7a4282041b2564bb1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page