Skip to main content

A parser for fc configuration files with support for complex structures, variables, and environment-aware configurations

Project description

FlyConf Parser

FlyConf Parser 是一个用于解析fc配置文件格式的Python库。fc配置文件是一种具有特定语法的配置格式,支持复杂的数据结构、变量引用和环境感知配置。

特性

  • 词法分析器,支持识别fc配置文件中的各种标记
  • 语法分析器,构建配置块的抽象语法树
  • 数据模型,用于表示解析后的配置结构
  • 字符串处理(原生多行字符串和单行字符串)
  • 变量引用系统(支持外部变量、环境变量和配置内引用)
  • 列表解析(简单列表和嵌套列表)
  • 导入导出功能(支持JSON格式)
  • 环境感知配置合并

安装

pip install flyconf

使用方法

基本用法

from flyconf.parser import FCConfigParser

# 解析fc配置文件
config = FCConfigParser.parse_file("config.fc")

# 访问配置块
block = config.get_block("server")
print(block.data)

# 导出为JSON
import json
json_data = config.to_json()

fc配置文件语法

fc配置文件具有以下语法结构:

@block_name(meta_key>meta_value) data_key>data_value

示例:

@mysql_default(type>conf.db)
dbtype>mysql
host>localhost
port>3306
database>oax
user>root
password>1234

@remember_me(type>conf.txt)
username>admin
password>1234

@test_list
users>[user1,user2,user3]

字符串

使用 ^...^ 表示单行字符串,使用 ^^^...^^^ 表示多行字符串:

@get_users(type>conf.sql)
dbtype>mysql
sql>^
SELECT id, username, email FROM users
^

列表

使用 [...] 表示列表:

@test_list
users>[user1,user2,user3]

变量引用

使用 $(variable_name) 表示变量引用:

@server
path>$(config.path)

API

FCConfigParser

  • FCConfigParser.parse_text(text) - 从文本解析配置
  • FCConfigParser.parse_file(file_path) - 从文件解析配置

FCConfig

  • config.get_block(name) - 获取指定名称的块
  • config.add_block(block) - 添加块
  • config.to_dict() - 转换为字典
  • config.to_json() - 转换为JSON字符串

FCBlock

  • block.name - 块名称
  • block.meta - 元数据字典
  • block.data - 数据字典

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flyconf-0.1.0.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flyconf-0.1.0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file flyconf-0.1.0.tar.gz.

File metadata

  • Download URL: flyconf-0.1.0.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for flyconf-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b1778bb32b611f198166b486fc23f8cce6b23e67e62f5ad5c37631350ee01e62
MD5 8a1d9e9ef231bf2f22489789dfca6c02
BLAKE2b-256 4208e3187c1b3edac2ae95fb243a554246feac04af8b793c320ae0a5f174f1c2

See more details on using hashes here.

File details

Details for the file flyconf-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: flyconf-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for flyconf-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 71c8052ced34ea12bfd7771206e4e0c13fa4354a8c417bb5d0bbcc0df653ac80
MD5 39def6fd9f1a2157c61731f3ed5c1c80
BLAKE2b-256 d4d9c8f8964bdc331c820962c03e8766a5c3ee589ef360b13635d16eedfc71c9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page