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

示例:

&&global_host>localhost
&&global_port>3306

@mysql_default(type>conf.db)
dbtype>mysql
host>$(global_host)
port>$(global_port)
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
# 简单值列表
numbers>1,2,3,4,5

# 对象列表
users>[id>1 name>Alice],[id>2 name>Bob]

变量引用

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

@server
path>$(config.path)

全局变量

使用 &&variable_name>value 声明全局变量:

&&default_host>localhost
&&default_port>3306

@mysql_config
host>$(default_host)
port>$(default_port)

跨文件引用

使用点号表示从属关系,引用其他文件中的属性:

&&db_host>database_config.fc.mysql.host
&&db_port>database_config.fc.mysql.port

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-1.0.2.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

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

flyconf-1.0.2-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for flyconf-1.0.2.tar.gz
Algorithm Hash digest
SHA256 5d20f46a1c1d662db4c00160073739e5560640b7eb49b12f88b3f4925f1af75c
MD5 8db95a5a0f7c37ba7e3cfd1f9e358654
BLAKE2b-256 09dd9bf04f0ba7b3ad5bc93a0370c0c09bb914cbc4df870175ee3904c59b98c1

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for flyconf-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c356fa4c04e2baf221052bfb772f157f24bc6faee2f9ce1162ea4ad8794facca
MD5 a9c3ea6fa8bc2212b8d0d40a5243803d
BLAKE2b-256 3d7c7276a75895f2aacd11d539ab6101d830fcfa5e44f90c15f07337899217e3

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