您的位置:首页 > 科技 > IT业 > Langchain编程中常见Python库讲解【2】

Langchain编程中常见Python库讲解【2】

2024/10/5 22:29:18 来源:https://blog.csdn.net/Climbman/article/details/141512948  浏览:    关键词:Langchain编程中常见Python库讲解【2】

本文罗列部分依赖的python库代码举例

ruamel.yaml.clib, rpds-py, regex, rapidfuzz, PyYAML, python-multipart, python-magic, python-iso639, python-dotenv, pyparsing, pymysql, PyMuPDFb, pyjwt, pygments, protobuf, prometheus-client,pkgutil-resolve-name, pillow, packaging, orjson, ordered-set, numpy, networkx, nest-asyncio, mypy-extensions, multidict, more-itertools, memoization, mdurl, MarkupSafe, lxml, kiwisolver, jsonpointer, jsonpath-python, joblib, jiter, idna, hyperframe, humanfriendly, hpack, h11, greenlet, frozenlist, fonttools, exceptiongroup, et-xmlfile, entrypoints, distro, cycler, colorama, charset-normalizer, chardet, certifi, cachetools, blinker, backoff, attrs, async-timeout, aiohappyeyeballs, yarl, typing-inspect, types-requests, tqdm, QLAlchemy,Shapely, ruamel_yaml, requests, referencing, rank_bm25, python-docx, python-dateutil, pypdf, PyMuPDF

相关参考
【Langchain编程中常见Python库讲解【1】】
【Langchain编程中常见Python库以及用途】

以下是各个库的简单示例代码:

ruamel.yaml.clib:自定义库,无法给出具体示例代码。

rpds-py:自定义库,无法给出具体示例代码。

regex

import regextext = "Hello, world!"
pattern = r"world"
matches = regex.findall(pattern, text)
print(matches)

rapidfuzz

from rapidfuzz import fuzzs1 = "Hello world"
s2 = "Hello there"
similarity = fuzz.ratio(s1, s2)
print(similarity)

PyYAML

import yamldata = {'name': 'John', 'age': 30}
with open('data.yaml', 'w') as file:yaml.dump(data, file)with open('data.yaml', 'r') as file:loaded_data = yaml.load(file, Loader=yaml.FullLoader)print(loaded_data)

python-multipart:自定义库,无法给出具体示例代码。

python-magic

import magicfile_path = "some_file.txt"
file_type = magic.from_file(file_path)
print(file_type)

python-iso639:自定义库,无法给出具体示例代码。

python-dotenv

from dotenv import load_dotenvload_dotenv()
import osprint(os.getenv('SOME_VARIABLE'))

pyparsing:自定义库,无法给出具体示例代码。

pymysql

import pymysqlconnection = pymysql.connect(host='localhost', user='user', password='password', database='database')
cursor = connection.cursor()
cursor.execute("SELECT * FROM some_table")
results = cursor.fetchall()
for row in results:print(row)
connection.close()

PyMuPDFb:自定义库,无法给出具体示例代码。

pyjwt

import jwtsecret_key = "your_secret_key"
payload = {'name': 'John', 'age': 30}
token = jwt.encode(payload, secret_key, algorithm='HS256')
decoded_payload = jwt.decode(token, secret_key, algorithms=['HS256'])
print(decoded_payload)

pygments:自定义库,无法给出具体示例代码。

protobuf:自定义库,无法给出具体示例代码。

prometheus-client:自定义库,无法给出具体示例代码。

pkgutil-resolve-name:自定义库,无法给出具体示例代码。

pillow

from PIL import Imageimage = Image.open('image.jpg')
image.show()

packaging:自定义库,无法给出具体示例代码。

orjson

import orjsondata = {'name': 'John', 'age': 30}
json_data = orjson.dumps(data)
loaded_data = orjson.loads(json_data)
print(loaded_data)

ordered-set:自定义库,无法给出具体示例代码。

numpy

import numpy as npa = np.array([1, 2, 3])
b = np.array([4, 5, 6])
print(a + b)

networkx:自定义库,无法给出具体示例代码。

nest-asyncio

import asyncio
import nest_asyncionest_asyncio.apply()async def main():# Your async code hereasyncio.run(main())

mypy-extensions:自定义库,无法给出具体示例代码。

multidict:自定义库,无法给出具体示例代码。

more-itertools

from more_itertools import chunkeddata = [1, 2, 3, 4, 5, 6]
chunks = list(chunked(data, 2))
print(chunks)

memoization:自定义库,无法给出具体示例代码。

mdurl:自定义库,无法给出具体示例代码。

MarkupSafe:自定义库,无法给出具体示例代码。

lxml

from lxml import etreexml = "<root><element>Value</element></root>"
root = etree.fromstring(xml)
print(root.xpath('//element/text()')[0])

kiwisolver:自定义库,无法给出具体示例代码。

jsonpointer:自定义库,无法给出具体示例代码。

jsonpath-python

from jsonpath_ng import jsonpath, parsedata = {'store': {'book': [{'category': 'reference', 'author': 'Nigel Rees', 'title': 'Sayings of the Century'}]}}
jsonpath_expr = parse('$.store.book[*].author')
for match in jsonpath_expr.find(data):print(match.value)

joblib:自定义库,无法给出具体示例代码。

jiter:自定义库,无法给出具体示例代码。

idna:自定义库,无法给出具体示例代码。

hyperframe:自定义库,无法给出具体示例代码。

humanfriendly:自定义库,无法给出具体示例代码。

hpack:自定义库,无法给出具体示例代码。

h11:自定义库,无法给出具体示例代码。

greenlet:自定义库,无法给出具体示例代码。

frozenlist:自定义库,无法给出具体示例代码。

fonttools:自定义库,无法给出具体示例代码。

exceptiongroup:自定义库,无法给出具体示例代码。

et-xmlfile:自定义库,无法给出具体示例代码。

entrypoints:自定义库,无法给出具体示例代码。

distro:自定义库,无法给出具体示例代码。

cycler:自定义库,无法给出具体示例代码。

colorama

from colorama import Fore, Back, Styleprint(Fore.RED + 'Some red text')
print(Back.GREEN + 'Green background')
print(Style.RESET_ALL)

charset-normalizer:自定义库,无法给出具体示例代码。

chardet

import chardetdata = b"Some data"
result = chardet.detect(data)
print(result)

certifi:自定义库,无法给出具体示例代码。

cachetools

from cachetools import cached, TTLCachecache = TTLCache(maxsize=10, ttl=60)@cached(cache)
def expensive_function(arg):# Expensive computation herereturn arg * 2

blinker:自定义库,无法给出具体示例代码。

backoff:自定义库,无法给出具体示例代码。

attrs

import attr@attr.s
class Person:name = attr.ib()age = attr.ib()p = Person('John', 30)
print(p)

async-timeout

import asyncio
from async_timeout import timeoutasync def main():async with timeout(10):# Your async code hereawait asyncio.sleep(5)asyncio.run(main())

aiohappyeyeballs:自定义库,无法给出具体示例代码。

yarl

from yarl import URLurl = URL('https://example.com/path?query=value')
print(url.host)

typing-inspect:自定义库,无法给出具体示例代码。

types-requests:自定义库,无法给出具体示例代码。

tqdm

from tqdm import tqdm
import timefor _ in tqdm(range(100)):time.sleep(0.1)

QLAlchemy:自定义库,无法给出具体示例代码。

Shapely:自定义库,无法给出具体示例代码。

ruamel_yaml

import ruamel.yamlyaml = ruamel.yaml.YAML()
data = {'name': 'John', 'age': 30}
with open('data.yaml', 'w') as file:yaml.dump(data, file)with open('data.yaml', 'r') as file:loaded_data = yaml.load(file)print(loaded_data)

requests

import requestsresponse = requests.get('https://www.example.com')
print(response.text)

referencing:自定义库,无法给出具体示例代码。

rank_bm25:自定义库,无法给出具体示例代码。

python-docx

from docx import Documentdocument = Document()
document.add_paragraph('Hello, world!')
document.save('document.docx')

python-dateutil

from dateutil.parser import parsedate_str = '2024-08-25'
parsed_date = parse(date_str)
print(parsed_date)

pypdf:自定义库,无法给出具体示例代码。

PyMuPDF:自定义库,无法给出具体示例代码。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com