Package: prismic-httpx
Asyncio alternative of the Python client for prismic.ioDisclaimer: I am not affiliated with the Prismic team and do not provide professional support.TheAsyncparadigm and the async/await syntax
(introduced in version 3.5) are Python code styles that can be used to write concurrent coroutines.
The support for this code style is still sparse in the Python community's libraries.You may find that the existingPrismic Python SDK,
based on therequestslibrary cannot be used with the async/await
syntax.
Hence its architecture is not optimal for use with natively async webservers likesanicor tornado.The emerging standard HTTP client for the Python asyncio community ishttpx,
which the current package uses.Getting startedInstall the kit for your projectSimply run:pip install prismic-httpxGet started with prismic.ioYou can find outhow to get started with prismic.ioon ourprismic.io developer's portal.Get started using the kitAlso on ourprismic.io developer's portal, on top of our full documentation, you will:get a thorough introduction ofhow to use prismic.io kits, including this one.seewhat else is available for Python: starter projects, examples, ...Kit's detailed documentationYou can find the documentation of the Python kit right here:http://prismic.readthedocs.org/en/latest/Here is a basic example of use:
(You can directly run it in a IPython console or in an async Python console:python -m asyncio)>>>importprismic>>>asyncwithprismic.get("http://your-repo.prismic.io/api","access_token")asapi:...doc=awaitapi.get_by_uid("speculoos-macaron")>>>doc.get_text("product.name")u'Speculoos Macaron'Using Memcached (or any other cache)By default, the kit will use a basicin-memory cache.For use of more advanced caches (Redis, memcached), seeaiocacheFor caching the requests in memory:>>>fromaiocacheimportCache>>>asyncwithprismic.get("http://your-rep.prismic.io/api","access_token",Cache(Cache.MEMORY))asapi:...[...]Note: The official asyncio library currently provides no support offiles I/Othe ShelveCache object might be introduced again in the future usingaiofilesif I get time.Using a Custom Request HandlerBy default, the kit will use an httpx clienthttpx.
You can override the client parameters in this way:>>>importprismic...>>>headers={'X-Auth':'from-client'}>>>params={'client_id':'client1'}>>>client_kwargs={headers:headers,params:params}...>>>asyncwithprismic.get("http://your-repo.prismic.io/api","access_token",**client_kwargs)asapi:...doc=awaitapi.get_by_uid("speculoos-macaron")>>>doc.get_text("product.name")u'Speculoos Macaron'You can also monkey patch the client itself with your own in such a way:>>>importprismic>>>importhttpx>>>headers={'X-Auth':'from-client'}>>>params={'client_id':'client1'}>>>withhttpx.AsyncClient(headers=headers,params=params)asclient:...api=prismic.get_with_client("http://your-rep.prismic.io/api","access_token",client=client)...[...]ChangelogNeed to see what changed, or to upgrade your kit? We keep our changelog onthis repository's "Releases" tab.Contribute to the kitContribution is open to all developer levelsInstall the kit locallyThis kit gets installed like any Python library.TestPlease write tests for any bugfix or new feature.If you find existing code that is not optimally tested and wish to make it better, we really appreciate it; but you should document it on its own branch and its own pull request.You can launch tests using:pytest test.DocumentationPlease document any bugfix or new feature.If you find existing code that is not optimally documented and wish to make it better, we really appreciate it; but you should document it on its own branch and its own pull request.LicenceThis software is licensed under the Apache 2 license, quoted below.Licensed under the Apache License, Version 2.0 (the "License"); you may not use this project except in compliance with the License. You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0.Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.