© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Cloudflare DevelopersCD
Cloudflare Developers•3y ago
sean

Is it possible to use the python "pickle" module with workers?

I'm trying to create a worker to run my ML model. It is a pickled model. I'm trying to import the pickle module, however, transcrypt says it is not found. I see it is a native CPython module which transcrypt says they have support for some modules, however, I get an error that says:
Error while compiling (offending file last):
        File '/Users/sean/Projects/alqen/apps/rhino/ai/sales-estimator/jon-sales-estimator/cloudflare-worker/index.py', line 1, at import of:
        File 'pickle', line 152, namely:

        Can't import module 'pickle'

Aborted
Error while compiling (offending file last):
        File '/Users/sean/Projects/alqen/apps/rhino/ai/sales-estimator/jon-sales-estimator/cloudflare-worker/index.py', line 1, at import of:
        File 'pickle', line 152, namely:

        Can't import module 'pickle'

Aborted


This is my code:
import pickle


def handleRequest(request):
    with open('./full_model_dict.pkl', 'rb') as handle:
        cat_model_dict = pickle.load(handle)

    test_feat_vec = [1334134.0, 6172404.0, 5753260.0, 1.0, 1.0]

    res = cat_model_dict.predict(test_feat_vec)

    return __new__(Response(res, {
        'headers': {'content-type': 'text/plain'}
    }))


addEventListener(
    'fetch', (lambda event: event.respondWith(handleRequest(event.request))))
import pickle


def handleRequest(request):
    with open('./full_model_dict.pkl', 'rb') as handle:
        cat_model_dict = pickle.load(handle)

    test_feat_vec = [1334134.0, 6172404.0, 5753260.0, 1.0, 1.0]

    res = cat_model_dict.predict(test_feat_vec)

    return __new__(Response(res, {
        'headers': {'content-type': 'text/plain'}
    }))


addEventListener(
    'fetch', (lambda event: event.respondWith(handleRequest(event.request))))


Has anyone attempted to use pickle with cloudflare workers before? I have a hunch that its probably not supported given the transpilation w/ WASM but just wanted to be sure.
Cloudflare Developers banner
Cloudflare DevelopersJoin
Welcome to the official Cloudflare Developers server. Here you can ask for help and stay updated with the latest news
85,042Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Is it possible to use WebSocket clients in workers?
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
2y ago
Is it possible to store data temporary to use it in between workers?
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
2y ago
Is it possible to use spanner nodejs client library in workers?
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
13mo ago
How to import XML file as js module in Workers? Is it possible?
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
3y ago