Rust-based Python wrapper for duckling library in Haskell.
Project description
PyDuckling
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.12
- 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) |
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
File details
Details for the file pyduckling_native_phihos-0.2.0-cp312-cp312-musllinux_1_2_x86_64.whl
.
File metadata
- Download URL: pyduckling_native_phihos-0.2.0-cp312-cp312-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 12.9 MB
- Tags: CPython 3.12, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d59a4aac80b672756009521ec2a397a5cdf358feaa68e0d386ba30c41200f3d |
|
MD5 | e7b05e85523f3190a365383161a6461b |
|
BLAKE2b-256 | 8e4ad213e7cfbffd33141d24a1fa4f60abe5f2063c655ec575ebad149a45c734 |
Provenance
File details
Details for the file pyduckling_native_phihos-0.2.0-cp312-cp312-manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: pyduckling_native_phihos-0.2.0-cp312-cp312-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 13.0 MB
- Tags: CPython 3.12, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7391852727cef9438c2e1d3aff5d3a54d0b3eea4ab9de3e8db7cd25a6663f384 |
|
MD5 | b25c729acffa4d0a620efeba2b093170 |
|
BLAKE2b-256 | 319018e14542449923736a100ef95706b4c7a055aa55b304996f41b902f7bce6 |
Provenance
File details
Details for the file pyduckling_native_phihos-0.2.0-cp311-cp311-musllinux_1_2_x86_64.whl
.
File metadata
- Download URL: pyduckling_native_phihos-0.2.0-cp311-cp311-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 12.9 MB
- Tags: CPython 3.11, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04f26b66a22f3209571d2bab0994989dc10aaa38b8f7527c3f0fd441e1c4143d |
|
MD5 | 868f2575e3b3e686eaca8eb034660a37 |
|
BLAKE2b-256 | 33139a059cfc4e4e316d6f8fff65d76266d130e364e0db9d7a5201933d55d51d |
Provenance
File details
Details for the file pyduckling_native_phihos-0.2.0-cp311-cp311-manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: pyduckling_native_phihos-0.2.0-cp311-cp311-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 13.0 MB
- Tags: CPython 3.11, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9de89de5f07af63987b45dbf33b70c19b9639cc150b74d68fca365f8a3ee26a |
|
MD5 | 5b984266363ab0d788bc3d0621ef07fb |
|
BLAKE2b-256 | b7ad155b55b0b7738dab2e00909d2643d2dd1c7519a0fd0b33dee6e644ca72e1 |
Provenance
File details
Details for the file pyduckling_native_phihos-0.2.0-cp310-cp310-musllinux_1_2_x86_64.whl
.
File metadata
- Download URL: pyduckling_native_phihos-0.2.0-cp310-cp310-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 12.9 MB
- Tags: CPython 3.10, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea13d6ad4933d4ac27dc62ccea64bce68fa0aeddddea09a5be2640855cb3e00f |
|
MD5 | 4e5057b916546bf6cd2f7a94096cd98e |
|
BLAKE2b-256 | 41e7c4e628cf1e7313b9b4bf01b653e59592cbf381d2eb9b894eeb3cfd9095c0 |
Provenance
File details
Details for the file pyduckling_native_phihos-0.2.0-cp310-cp310-manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: pyduckling_native_phihos-0.2.0-cp310-cp310-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 13.0 MB
- Tags: CPython 3.10, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ff3cfef4f9165b9a2dd5103fc0439a102bfc62ad8587c9bb6e12e282487b7f7 |
|
MD5 | cd065b55f098b438f0c06e8abeae2c5c |
|
BLAKE2b-256 | 101ebfabcb90bfcbb4aab1bb302221addbf1e607fddf232b1ab7dc429be36087 |
Provenance
File details
Details for the file pyduckling_native_phihos-0.2.0-cp39-cp39-musllinux_1_2_x86_64.whl
.
File metadata
- Download URL: pyduckling_native_phihos-0.2.0-cp39-cp39-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 12.9 MB
- Tags: CPython 3.9, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e474a697847ff424bdd3bd1c675871661d757bc367d7aa840f7a7aa49dc3bb86 |
|
MD5 | 1e254f7c89f114056b5bcf99f310c3ee |
|
BLAKE2b-256 | 8aedf9e5d053ff2cffa8e4d079cd03a6c1c1b1c2999e2a5a6d6f3edadeeafaf4 |
Provenance
File details
Details for the file pyduckling_native_phihos-0.2.0-cp39-cp39-manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: pyduckling_native_phihos-0.2.0-cp39-cp39-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 13.0 MB
- Tags: CPython 3.9, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75bf78efae316729e6a645db98094db7ed09de5eae2b48e8968e175cb6773f97 |
|
MD5 | 1554d8814d130661a652bdbea7279b25 |
|
BLAKE2b-256 | 157ed5987aae5f2743bb7b9e8497e08ddce3be294ece663895bd96ca5d977acf |
Provenance
File details
Details for the file pyduckling_native_phihos-0.2.0-cp38-cp38-musllinux_1_2_x86_64.whl
.
File metadata
- Download URL: pyduckling_native_phihos-0.2.0-cp38-cp38-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 12.9 MB
- Tags: CPython 3.8, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27091ab01e54afefd440a4c10d981bdba00f9f7da07008ea39df17cade874e44 |
|
MD5 | 2c576906083190584765fe075c369df8 |
|
BLAKE2b-256 | 9a9073c944e3c714fdf2a6527074fea3423558295e4dc1356673cc4b0ef7b267 |
Provenance
File details
Details for the file pyduckling_native_phihos-0.2.0-cp38-cp38-manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: pyduckling_native_phihos-0.2.0-cp38-cp38-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 13.0 MB
- Tags: CPython 3.8, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33bcefbe1999583a2abcb7dbbbd1008445db71bcd825d40e1b45f9e25dcfcec6 |
|
MD5 | cd6035133e3e3c5cf7aab90b88a27937 |
|
BLAKE2b-256 | f480dd7b5981af666128dc736a9455efce8aa60b3929aad804ff693fff59d40f |