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
  • Supported platforms: x86_64 Linux and macOS ARM64 (Apple Silicon)

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

ℹ️ We provide package distributions for Linux (x86_64) and macOS (ARM64/Apple Silicon).

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)
0.4.0 v0.2.0.1 (commit 59a13ff)

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.

Special Thanks

  • @evanscastonguay for building the first working macOS ARM64 proof-of-concept and providing the research that made Apple Silicon support possible.

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.4.0-cp314-cp314-musllinux_1_2_x86_64.whl (17.2 MB view details)

Uploaded CPython 3.14musllinux: musl 1.2+ x86-64

pyduckling_native_phihos-0.4.0-cp314-cp314-manylinux_2_28_x86_64.whl (17.1 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64

pyduckling_native_phihos-0.4.0-cp314-cp314-macosx_11_0_arm64.whl (17.1 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pyduckling_native_phihos-0.4.0-cp313-cp313-musllinux_1_2_x86_64.whl (17.2 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

pyduckling_native_phihos-0.4.0-cp313-cp313-manylinux_2_28_x86_64.whl (21.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

pyduckling_native_phihos-0.4.0-cp313-cp313-macosx_11_0_arm64.whl (17.1 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyduckling_native_phihos-0.4.0-cp312-cp312-musllinux_1_2_x86_64.whl (17.2 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

pyduckling_native_phihos-0.4.0-cp312-cp312-manylinux_2_28_x86_64.whl (17.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

pyduckling_native_phihos-0.4.0-cp312-cp312-macosx_11_0_arm64.whl (17.1 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyduckling_native_phihos-0.4.0-cp311-cp311-musllinux_1_2_x86_64.whl (17.2 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

pyduckling_native_phihos-0.4.0-cp311-cp311-macosx_11_0_arm64.whl (17.1 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyduckling_native_phihos-0.4.0-cp310-cp310-musllinux_1_2_x86_64.whl (17.2 MB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

pyduckling_native_phihos-0.4.0-cp310-cp310-manylinux_2_28_x86_64.whl (17.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

pyduckling_native_phihos-0.4.0-cp310-cp310-macosx_11_0_arm64.whl (17.1 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyduckling_native_phihos-0.4.0-cp39-cp39-musllinux_1_2_x86_64.whl (17.2 MB view details)

Uploaded CPython 3.9musllinux: musl 1.2+ x86-64

pyduckling_native_phihos-0.4.0-cp39-cp39-manylinux_2_28_x86_64.whl (17.1 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ x86-64

pyduckling_native_phihos-0.4.0-cp38-cp38-manylinux_2_28_x86_64.whl (17.1 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.28+ x86-64

File details

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

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.4.0-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 89be5311442f0bf4e3af63620d41366b0364d678435b94a0d6e3551f00461e27
MD5 a6ead9336259a86148e41c728739edca
BLAKE2b-256 e9980df653dbca7722335ab69b22e290632f9b7b5e6137bca7fec131ba8075aa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.4.0-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 31b2c8f5d7df4a4b2897a96bc2e5f5955ecd98c4c01e9fb653fc4270a68d28dc
MD5 9cf3ea9de3b16d3c852346820b0a1859
BLAKE2b-256 18b2886ac8b973f3490e35743d51c005cf9f110bbf75f3c84b52d5d81c2e508e

See more details on using hashes here.

File details

Details for the file pyduckling_native_phihos-0.4.0-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.4.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 98026575382eda4cefb6e06bc6752ee62e6ddecad03082dc51b1b87daa848f23
MD5 134159fe10d6fd842f98ce61943bce32
BLAKE2b-256 422a050015d7998ca31e2b976ad993016690d67f11e6e1b83ca28bdc69587293

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.4.0-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 0a270126ea99299f04ca57360d157b4b9a35a8ef7f8eda5d80b21b0e61e5c283
MD5 21850eee4ad32d3b6346caedf74b41c4
BLAKE2b-256 cb9c93ceb213c2df6de0b472ff68c232b0ddffb42abe4aa1c8e7cee4a9ddbccd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.4.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 61d87080ddfd3d55480377c8e149539bd7de8100cb267c932ea9156a219fcb46
MD5 fa797c7c1c6b6f09912cc7ad23192879
BLAKE2b-256 ca03262d9baf0cbc3efbb19b29e47ae5d83fb1c2692ec608223439e42cdfaa18

See more details on using hashes here.

File details

Details for the file pyduckling_native_phihos-0.4.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.4.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6ea6ceaa7b9428f3b9762e721cf111853d7c7bef50769b279497873031e27ec4
MD5 d55358625d9e1d61838aa9b34d0e2f83
BLAKE2b-256 353e9f2ed45350be5d8a45c0f9133afd13fbc1305df40a7dd680905993f39039

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.4.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 519d78d11384c4b21b02a80c099071eb5a0cfdc68385584874c8d664db2a8109
MD5 21e99a04f9df8c1235bd8f2ae57e9354
BLAKE2b-256 ee604aadd8cb8cf3e3f9d9e1d4f175ad75162b5966dbbf028df76aa14dbe4d3f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.4.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0a21dcf2647df842275b3ff77fd7ebd7086665387ebcb415a7b908c5a4bbcb19
MD5 2c7c5e9b5b725be4908fa5b6b8b6bc0c
BLAKE2b-256 654f298098cb1351aa87a8e55a2f87a58abce22e0f8e5d1fd559238375110cae

See more details on using hashes here.

File details

Details for the file pyduckling_native_phihos-0.4.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.4.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c95357f42542c7785244cbb84e48f306034d831720a4b5526d6bd22699c0c7c3
MD5 ca33efa60f1c8008472350cfcf0e5ce0
BLAKE2b-256 5840116b0a3eacad9f7140a1b69400451ead51c6be8e1f5899654d5c9668b463

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.4.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 fd1afefd977a9718d38dd85fb9c0aa32ebfec234a5e4e68ecc4ab59e3a32c139
MD5 a0886f0154b8a61f7f36f7c75baabfdf
BLAKE2b-256 f87ec776fa4cb7a1238003f4e0a6b5349b134ac8cb5a08bfaadf922186ff39b7

See more details on using hashes here.

File details

Details for the file pyduckling_native_phihos-0.4.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.4.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c790acaeb28109f9a44ccd8d8f589ce1d0936dbfafff0769526aafcf809c63e5
MD5 2a2f5bfb51464397643be796793ac04a
BLAKE2b-256 b13ec2b5ca9e64e40fc4dfed2d5d3d4f6f215c5a026b0bfc703f828418ff6cbf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.4.0-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 78dc606ac6b87299b0516bea89818bcd5798a4253fdc1db5ee5bbc1d177b3d7c
MD5 f8b8a55c9619f48d03ecc7b128fc1dbc
BLAKE2b-256 0bc765ebe568cdba9e2f917075626eb4518955817d867343022a28467e79ca3e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.4.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9f69853724624ecd32887d89400d1bba84ab7d56540386a60db97a8df2f5eccb
MD5 91f8233c4d2654266307a3ad45b93c5d
BLAKE2b-256 089976cab3bdfa273fa4350a0b107005e2095f78e00e966cb004626419e523d5

See more details on using hashes here.

File details

Details for the file pyduckling_native_phihos-0.4.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.4.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4f218d4b5ef9749d4a1f9a93ec11e5fb48d551de9072801e5c95c90789fc24bd
MD5 33d237e63ec9e5d666570b660fe51818
BLAKE2b-256 41d6a78b42de0a46225e3938115aaf68c181a4981216a7458983aa41867da0cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.4.0-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9833dc2c0ca4961b101e7afdac2034f5acc7ed46b2d8cc87fa64c1baa6d15b79
MD5 987147239adc0bd4e801c0a442c8863b
BLAKE2b-256 b957f24cb69738d243f728df1c972d15ae4ab5361962f9896e1abde08d484329

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.4.0-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3d14e1035e7ddb64138defcc56ae044987a410b15ffc4da0826f35f126052749
MD5 e602f47cb3caa75eccd4039fb4f12ac7
BLAKE2b-256 58cd1bdc9572e28e3657990c2676841a34730dc8ae8661359db1f8510cd001d8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.4.0-cp38-cp38-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 67ddc38082101beb5b07cd36b7c3b0e7d8eb90dcec0362b53b88a3d7261523ff
MD5 f66c124e09e11a7e733375d8cd17c518
BLAKE2b-256 edb1b765253565ad10894bfd98d7d992f14de15085cb6e36de4692ab5f344ed9

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