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 regex

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

rapidfuzz

from rapidfuzz import fuzz

s1 = "Hello world"
s2 = "Hello there"
similarity = fuzz.ratio(s1, s2)
print(similarity)

PyYAML

import 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, Loader=yaml.FullLoader)
    print(loaded_data)

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

python-magic

import magic

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

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

python-dotenv

from dotenv import load_dotenv

load_dotenv()
import os

print(os.getenv('SOME_VARIABLE'))

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

pymysql

import pymysql

connection = 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 jwt

secret_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 Image

image = Image.open('image.jpg')
image.show()

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

orjson

import orjson

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

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

numpy

import numpy as np

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

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

nest-asyncio

import asyncio
import nest_asyncio

nest_asyncio.apply()

async def main():
    # Your async code here

asyncio.run(main())

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

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

more-itertools

from more_itertools import chunked

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

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

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

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

lxml

from lxml import etree

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

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

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

jsonpath-python

from jsonpath_ng import jsonpath, parse

data = {'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, Style

print(Fore.RED + 'Some red text')
print(Back.GREEN + 'Green background')
print(Style.RESET_ALL)

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

chardet

import chardet

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

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

cachetools

from cachetools import cached, TTLCache

cache = TTLCache(maxsize=10, ttl=60)

@cached(cache)
def expensive_function(arg):
    # Expensive computation here
    return 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 timeout

async def main():
    async with timeout(10):
        # Your async code here
        await asyncio.sleep(5)

asyncio.run(main())

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

yarl

from yarl import URL

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

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

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

tqdm

from tqdm import tqdm
import time

for _ in tqdm(range(100)):
    time.sleep(0.1)

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

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

ruamel_yaml

import ruamel.yaml

yaml = 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 requests

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

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

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

python-docx

from docx import Document

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

python-dateutil

from dateutil.parser import parse

date_str = '2024-08-25'
parsed_date = parse(date_str)
print(parsed_date)

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

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

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值