-
-
Notifications
You must be signed in to change notification settings - Fork 129
Additionally expose multidict as a Cython importable #1178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c26f06e
bac1e1d
2f43fb6
3ddfc53
35b7406
86e55a7
7461cf7
8fa2b7f
b44fee9
cc8ed9f
dd09781
2e64455
6af7486
24dba8c
aa40975
5b92228
036d674
387cf48
e4757c5
5ce8633
267899e
43171cf
fc358b4
dca5a77
c8df470
3200962
e7c12dd
9a8e0a6
6888d9c
7852607
d380215
6d697c8
726b325
e96eace
c9fc85c
e4abb6e
a9d760f
8ee6698
3e777e1
e7711d2
9607da7
9443cf0
5e1911f
a71dd22
fa9a01a
f4f5f83
493cafd
608b709
37d82bc
8af77cd
cd35076
6df3f53
3ec2fda
cf1a58a
a455930
0cf3a3e
e1775f6
d0db07e
637f874
c57e34a
dbc3a82
1f2b1a1
083a2af
b13bb5f
fceb11e
fdb402e
e6023f4
8451958
c07080c
51b0f3f
54351be
9886334
a775b83
0652d27
c0cc056
fc3e1be
d426c89
dd88a6c
fbac986
69f7c43
76b63a2
16701b6
c04c2f8
2279860
78a90cc
f50697a
faa13ac
cd5cbfb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Started exposing an interface for importing the :mod:`multidict` C-extension from downstream Cython libraries -- by :user:`Vizonex`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ graft requirements | |
| graft tests | ||
| global-exclude *.pyc | ||
| include multidict/*.c | ||
| include multidict/_multilib/*.h | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This adds the file to sdist. You may have to include it into wheels too.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will make sure I do so. Thanks for reminding me about wheels. I will get that done after I write some new documentation for using multidict with cython. |
||
| exclude multidict/_multidict.html | ||
| exclude multidict/*.so | ||
| exclude multidict/*.pyd | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| .. _cython-api: | ||
|
|
||
| ========== | ||
| Cython API | ||
| ========== | ||
|
|
||
| Multidicts implements a cython api that is used for speeding up the aiohttp http parser | ||
| but this feature can be used elsewhere in your own projects. | ||
|
|
||
|
|
||
| Introduction | ||
| ------------ | ||
| Multidict can be used with cython to speedup performance of other tools or | ||
| scripts you may think about programming. Those who are familliar with the way | ||
| `numpy <https://cython.readthedocs.io/en/latest/src/userguide/numpy_tutorial.html>`_ | ||
| works should know that this library works the exact same way. If your not familliar with this don't worry. | ||
|
|
||
| An example might be combining the node-js `llhttp <https://llhttp.org>`_ library | ||
| and Multidict together for example (which is something aiohttp already | ||
| does) . By using llhttp's callback functions on items such as HTTP headers and URL | ||
| query arguments you can build some extremely fast parsers and more | ||
| with extra performance benefits included. | ||
|
|
||
|
|
||
| Functions for using MultiDict in cython | ||
| should have very simillar feel and format to the way CPython was written. e.g.: | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| from multidict cimport import_multidict, MultiDict, MultiDict_Add | ||
| # always remeber to call import_multidict before anything else | ||
| # otherwise your compilation will fail | ||
| import_multidict() | ||
|
|
||
| cdef MultiDict create_with_user_agent_header(): | ||
| cdef MultiDict md = MultiDict() | ||
| MultiDict_Add(md, "user-agent", "Multidict-Made-User-Agent") | ||
| return md | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| Compiling | ||
| --------- | ||
| Compiling multidict with cython works the exact same way as *numpy* with the only | ||
| requirement being to link where the headers needed to compile the library are kept | ||
| luckily multidict includes a function to get where the headers are stored called | ||
| *get_include* and it is no different from the way `numpy works <https://cython.readthedocs.io/en/latest/src/userguide/numpy_tutorial.html#compilation-using-setuptools>`_. | ||
| e.g.: | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| from Cython.Build import cythonize | ||
| from setuptools import Extension, setup | ||
| import multidict | ||
|
|
||
| if __name__ == "__main__": | ||
| setup( | ||
| ext_modules=cythonize( | ||
| Extension( | ||
| "your_module.pyx", sources=["your_module.pyx"] | ||
| ) | ||
| ), | ||
| # in here is where you could but down your include directories | ||
| include_dirs=[multidict.get_include()], | ||
| ) | ||
|
|
||
|
|
||
| Know that your are not limited to just one *include_dirs* directory in fact you could combine | ||
| *numpy* and *multidict* together if you really wanted to along with other C Libraries that you would | ||
| like to compile alongside it. e.g.: | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| from setuptools import Extension, setup | ||
| from Cython.Build import cythonize | ||
| import numpy | ||
| import multidict | ||
|
|
||
| extensions = [ | ||
| Extension("*", ["*.pyx"], | ||
| include_dirs=[ | ||
| numpy.get_include(), | ||
| multidict.get_include(), | ||
| "my-other-clibraries/path/etc" | ||
| ] | ||
| ), | ||
| ] | ||
| setup( | ||
| name="My hello app", | ||
| ext_modules=cythonize(extensions), | ||
| ) | ||
|
|
||
| There's | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -101,6 +101,7 @@ Contents | |
| multidict | ||
| benchmark | ||
| changes | ||
| in-cython | ||
|
|
||
| Indices and tables | ||
| ================== | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,6 +68,7 @@ multipart | |
| Multipart | ||
| mypy | ||
| Nikolay | ||
| numpy | ||
| param | ||
| params | ||
| performant | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where you can see a preview of how this change note is rendered: https://multidict--1178.org.readthedocs.build/en/1178/changes/. Alternatively, if you want to build the docs locally, it'll also include draft/unreleased notes.