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.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.
Metadata
Release files for pyduckling-native-phihos 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
Total release size: 295.6 MB
Release files / pyduckling_native_phihos-0.4.0-cp314-cp314-musllinux_1_2_x86_64.whl
| Download URL | pyduckling_native_phihos-0.4.0-cp314-cp314-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 17.2 MB |
| Tags | CPython 3.14 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
89be5311442f0bf4e3af63620d41366b0364d678435b94a0d6e3551f00461e27
|
|
BLAKE2b-256 checksum How to use checksums |
e9980df653dbca7722335ab69b22e290632f9b7b5e6137bca7fec131ba8075aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / pyduckling_native_phihos-0.4.0-cp314-cp314-manylinux_2_28_x86_64.whl
| Download URL | pyduckling_native_phihos-0.4.0-cp314-cp314-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 17.1 MB |
| Tags | CPython 3.14 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
31b2c8f5d7df4a4b2897a96bc2e5f5955ecd98c4c01e9fb653fc4270a68d28dc
|
|
BLAKE2b-256 checksum How to use checksums |
18b2886ac8b973f3490e35743d51c005cf9f110bbf75f3c84b52d5d81c2e508e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / pyduckling_native_phihos-0.4.0-cp314-cp314-macosx_11_0_arm64.whl
| Download URL | pyduckling_native_phihos-0.4.0-cp314-cp314-macosx_11_0_arm64.whl |
|---|---|
| Size | 17.1 MB |
| Tags | CPython 3.14 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
98026575382eda4cefb6e06bc6752ee62e6ddecad03082dc51b1b87daa848f23
|
|
BLAKE2b-256 checksum How to use checksums |
422a050015d7998ca31e2b976ad993016690d67f11e6e1b83ca28bdc69587293
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / pyduckling_native_phihos-0.4.0-cp313-cp313-musllinux_1_2_x86_64.whl
| Download URL | pyduckling_native_phihos-0.4.0-cp313-cp313-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 17.2 MB |
| Tags | CPython 3.13 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
0a270126ea99299f04ca57360d157b4b9a35a8ef7f8eda5d80b21b0e61e5c283
|
|
BLAKE2b-256 checksum How to use checksums |
cb9c93ceb213c2df6de0b472ff68c232b0ddffb42abe4aa1c8e7cee4a9ddbccd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / pyduckling_native_phihos-0.4.0-cp313-cp313-manylinux_2_28_x86_64.whl
| Download URL | pyduckling_native_phihos-0.4.0-cp313-cp313-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 21.5 MB |
| Tags | CPython 3.13 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
61d87080ddfd3d55480377c8e149539bd7de8100cb267c932ea9156a219fcb46
|
|
BLAKE2b-256 checksum How to use checksums |
ca03262d9baf0cbc3efbb19b29e47ae5d83fb1c2692ec608223439e42cdfaa18
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / pyduckling_native_phihos-0.4.0-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | pyduckling_native_phihos-0.4.0-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 17.1 MB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
6ea6ceaa7b9428f3b9762e721cf111853d7c7bef50769b279497873031e27ec4
|
|
BLAKE2b-256 checksum How to use checksums |
353e9f2ed45350be5d8a45c0f9133afd13fbc1305df40a7dd680905993f39039
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / pyduckling_native_phihos-0.4.0-cp312-cp312-musllinux_1_2_x86_64.whl
| Download URL | pyduckling_native_phihos-0.4.0-cp312-cp312-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 17.2 MB |
| Tags | CPython 3.12 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
519d78d11384c4b21b02a80c099071eb5a0cfdc68385584874c8d664db2a8109
|
|
BLAKE2b-256 checksum How to use checksums |
ee604aadd8cb8cf3e3f9d9e1d4f175ad75162b5966dbbf028df76aa14dbe4d3f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / pyduckling_native_phihos-0.4.0-cp312-cp312-manylinux_2_28_x86_64.whl
| Download URL | pyduckling_native_phihos-0.4.0-cp312-cp312-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 17.1 MB |
| Tags | CPython 3.12 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
0a21dcf2647df842275b3ff77fd7ebd7086665387ebcb415a7b908c5a4bbcb19
|
|
BLAKE2b-256 checksum How to use checksums |
654f298098cb1351aa87a8e55a2f87a58abce22e0f8e5d1fd559238375110cae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / pyduckling_native_phihos-0.4.0-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | pyduckling_native_phihos-0.4.0-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 17.1 MB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
c95357f42542c7785244cbb84e48f306034d831720a4b5526d6bd22699c0c7c3
|
|
BLAKE2b-256 checksum How to use checksums |
5840116b0a3eacad9f7140a1b69400451ead51c6be8e1f5899654d5c9668b463
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / pyduckling_native_phihos-0.4.0-cp311-cp311-musllinux_1_2_x86_64.whl
| Download URL | pyduckling_native_phihos-0.4.0-cp311-cp311-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 17.2 MB |
| Tags | CPython 3.11 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
fd1afefd977a9718d38dd85fb9c0aa32ebfec234a5e4e68ecc4ab59e3a32c139
|
|
BLAKE2b-256 checksum How to use checksums |
f87ec776fa4cb7a1238003f4e0a6b5349b134ac8cb5a08bfaadf922186ff39b7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / pyduckling_native_phihos-0.4.0-cp311-cp311-macosx_11_0_arm64.whl
| Download URL | pyduckling_native_phihos-0.4.0-cp311-cp311-macosx_11_0_arm64.whl |
|---|---|
| Size | 17.1 MB |
| Tags | CPython 3.11 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
c790acaeb28109f9a44ccd8d8f589ce1d0936dbfafff0769526aafcf809c63e5
|
|
BLAKE2b-256 checksum How to use checksums |
b13ec2b5ca9e64e40fc4dfed2d5d3d4f6f215c5a026b0bfc703f828418ff6cbf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / pyduckling_native_phihos-0.4.0-cp310-cp310-musllinux_1_2_x86_64.whl
| Download URL | pyduckling_native_phihos-0.4.0-cp310-cp310-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 17.2 MB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
78dc606ac6b87299b0516bea89818bcd5798a4253fdc1db5ee5bbc1d177b3d7c
|
|
BLAKE2b-256 checksum How to use checksums |
0bc765ebe568cdba9e2f917075626eb4518955817d867343022a28467e79ca3e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / pyduckling_native_phihos-0.4.0-cp310-cp310-manylinux_2_28_x86_64.whl
| Download URL | pyduckling_native_phihos-0.4.0-cp310-cp310-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 17.1 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
9f69853724624ecd32887d89400d1bba84ab7d56540386a60db97a8df2f5eccb
|
|
BLAKE2b-256 checksum How to use checksums |
089976cab3bdfa273fa4350a0b107005e2095f78e00e966cb004626419e523d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / pyduckling_native_phihos-0.4.0-cp310-cp310-macosx_11_0_arm64.whl
| Download URL | pyduckling_native_phihos-0.4.0-cp310-cp310-macosx_11_0_arm64.whl |
|---|---|
| Size | 17.1 MB |
| Tags | CPython 3.10 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
4f218d4b5ef9749d4a1f9a93ec11e5fb48d551de9072801e5c95c90789fc24bd
|
|
BLAKE2b-256 checksum How to use checksums |
41d6a78b42de0a46225e3938115aaf68c181a4981216a7458983aa41867da0cc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / pyduckling_native_phihos-0.4.0-cp39-cp39-musllinux_1_2_x86_64.whl
| Download URL | pyduckling_native_phihos-0.4.0-cp39-cp39-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 17.2 MB |
| Tags | CPython 3.9 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
9833dc2c0ca4961b101e7afdac2034f5acc7ed46b2d8cc87fa64c1baa6d15b79
|
|
BLAKE2b-256 checksum How to use checksums |
b957f24cb69738d243f728df1c972d15ae4ab5361962f9896e1abde08d484329
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / pyduckling_native_phihos-0.4.0-cp39-cp39-manylinux_2_28_x86_64.whl
| Download URL | pyduckling_native_phihos-0.4.0-cp39-cp39-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 17.1 MB |
| Tags | CPython 3.9 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
3d14e1035e7ddb64138defcc56ae044987a410b15ffc4da0826f35f126052749
|
|
BLAKE2b-256 checksum How to use checksums |
58cd1bdc9572e28e3657990c2676841a34730dc8ae8661359db1f8510cd001d8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / pyduckling_native_phihos-0.4.0-cp38-cp38-manylinux_2_28_x86_64.whl
| Download URL | pyduckling_native_phihos-0.4.0-cp38-cp38-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 17.1 MB |
| Tags | CPython 3.8 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
67ddc38082101beb5b07cd36b7c3b0e7d8eb90dcec0362b53b88a3d7261523ff
|
|
BLAKE2b-256 checksum How to use checksums |
edb1b765253565ad10894bfd98d7d992f14de15085cb6e36de4692ab5f344ed9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Security for pyduckling-native-phihos 0.4.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.