ctext
ctext is a simple Python wrapper and set of helper functions for the CTP API, which fetches data from the Chinese Text Project database, a digital library of pre-modern Chinese literature. Requires Python 3 or later.
Development status
This software is currently experimental. See http://ctext.org/tools/api for API details.
Installation
pip install ctext
Usage
Textual items are identified by CTP URNs. Each URN identifies a text or part of a text. You can get these manually by visiting the http://ctext.org website (bottom-right of each page), or programmatically using the searchtexts() function. To use this library, first:
from ctext import *
Some API functions (like getting the full structure of a text, or downloading a lot of data) may require an API key. If you have one, before calling any other functions, do this:
setapikey("your-api-key-goes-here")
gettext
passages = gettext("ctp:analects/xue-er")
Simple wrapper around the gettext API call. Note that the API gettext function needs to be called recursively to get the full text of an entire book; the Python helper functions gettextasparagrapharray, gettextasstring, and gettextasobject call gettext repeatedly to extract all corresponding textual data.
gettextasobject
data = gettextasobject("ctp:analects/xue-er")
Returns the full text of the requested URN as an object with a nested structure representing what each gettext API call returns.
gettextasparagrapharray
passages = gettextasparagrapharray("ctp:analects/xue-er")
Returns the full text of the requested URN as a simple array of strings, each corresponding to one passage of text. Titles are omitted.
gettextasstring
string = gettextasstring("ctp:analects/xue-er")
Returns the full text of the requested URN as a single string. Each paragraph is separated with “nn”.
gettextinfo
data = gettextinfo("ctp:analects")
Simple wrapper around the gettextinfo API call.
searchtexts
data = searchtexts("論語")
Simple wrapper around the searchtexts API call.
setapikey
setapikey("your-api-key-goes-here")
This sets an API key which is then supplied to the CTP API with all subsequent API requests.
License
Copyright 2016 Donald Sturgeon. This code is licensed under the MIT License: http://opensource.org/licenses/mit-license.html
Metadata
Release files for ctext 0.15
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ctext-0.15.tar.gz | 3.2 kB | Without provenance | Details for ctext-0.15.tar.gz |
Release files / ctext-0.15.tar.gz
| Download URL | ctext-0.15.tar.gz |
|---|---|
| Size | 3.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
518ed63a85e7312e4ba910260427537974e6426e477f5b553ad2c93bc1d93d57
|
|
BLAKE2b-256 checksum How to use checksums |
60521f688e398a94a27afce3f726fdcd30cd83e1bf6f5647b8c891f1f65ca891
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for ctext 0.15
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.